Courbes

Couleur & alpha

Exemples:

x = np.arange(0, 10)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2, figsize=(12, 6))

ax1.plot(x, x + 0, color='0.0', label='0.0')
ax1.plot(x, x + 1, color='0.5', label='0.5')
ax1.plot(x, x + 2, color='1.0', label='1.0')
ax1.legend()

ax2.plot(x, x + 0, color=(1,0,0), label='(1,0,0)')
ax2.plot(x, x + 1, color=(1,0,0), alpha=0.5, label='(1,0,0) + alpha')
ax2.plot(x, x + 2, color=(1,0,0,.5), label='(1,0,0,0.5)')
ax2.legend()

ax3.plot(x, x + 0, color='#FF0000', label='#FF0000')
ax3.plot(x, x + 1, color='#FF0000', alpha=0.5, label='#FF0000 + alpha')
ax3.plot(x, x + 2, color='#ff000080', label='#ff000080')
ax3.legend()

ax4.plot(x, x + 0, color='red', label='red')
ax4.plot(x, x + 1, color='red', alpha=0.5, label='red + alpha')
ax4.legend()

x = np.arange(0, 10)

plt.plot(x, x + 0)
plt.plot(x, x + 1)
plt.plot(x, x + 2, color='C0')
plt.plot(x, x + 3, color='C1')

x = np.arange(0, 10)

plt.scatter(x, x, color='white', edgecolor='k')
plt.scatter(x, x + 1, color='k')


Style & épaisseur de ligne


Marqueurs


Fmt

Exemple:

axes.plot(x, x + 0, '-og', label="solid green")
axes.plot(x, x + 1, '--c', label="dashed cyan")
axes.plot(x, x + 2, '-.b', label="dashdot blue")
axes.plot(x, x + 3, ':r', label="dotted red")

Couleurs avec valeurs continues

Colormap reference
Choosing Colormaps
Using custom colormaps


Cycle

On peut modifier le cycle de couleur utilisé par un graphique

Exemple:

x = np.arange(0, 10)

cyclerA = plt.cycler(color=['r', 'g', 'b'])
cyclerB = plt.cycler(color=plt.get_cmap('Pastel1').colors)
cyclerC = plt.cycler(color=plt.get_cmap('jet')(np.linspace(0,1,3)))

fig = plt.figure(figsize=(12, 3))

for i, cycler in enumerate([cyclerA, cyclerB, cyclerC]):
    ax = fig.add_subplot(1, 3, i+1)
    ax.set_prop_cycle(cycler)
    ax.plot(x, x + 0)
    ax.plot(x, x + 1)
    ax.plot(x, x + 2)

Cycling through multiple properties