Utilisez plot pour dessiner un graphique linéaire. Quelques exemples sont présentés ci-dessous.
Passez les valeurs x, y séparément, comme plot (x, y). Vous pouvez spécifier le style de ligne avec le paramètre linestyle.
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
x = np.linspace(-6,6,1000)
ax.plot(x,norm.pdf(x, loc=0.0, scale=1.0), color='black', linestyle='solid')
ax.plot(x,norm.pdf(x, loc=0.0, scale=0.5), color='black', linestyle='dashed')
ax.plot(x,norm.pdf(x, loc=0.0, scale=0.25), color='black', linestyle='dashdot')
ax.set_title('First line plot')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.grid(True)
fig.show()

Vous pouvez modifier l'épaisseur de ligne avec la largeur de ligne.
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
x = np.linspace(-6,6,1000)
ax.plot(x,norm.pdf(x, loc=0.0, scale=1.0), color='black', linestyle='solid', linewidth = 3.0, label='line1')
ax.plot(x,norm.pdf(x, loc=0.0, scale=0.5), color='black', linestyle='dashed',linewidth = 1.0, label='line2')
ax.plot(x,norm.pdf(x, loc=0.0, scale=0.25), color='black', linestyle='dashdot', linewidth = 0.5,label='line3')
ax.set_title('Second line plot')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.legend()
ax.grid(True)
fig.show()

Changez la couleur de la ligne avec la couleur.
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
x = np.linspace(-6,6,1000)
ax.plot(x,norm.pdf(x, loc=0.0, scale=1.0), color='red', linestyle='solid', linewidth = 1.0)
ax.plot(x,norm.pdf(x, loc=0.0, scale=0.5), color='green',linestyle='solid',linewidth = 1.0)
ax.plot(x,norm.pdf(x, loc=0.0, scale=0.25), color='blue', linestyle='solid', linewidth = 1.0)
ax.set_title('Third line plot')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.grid(True)
fig.show()

Lorsque le marqueur est spécifié, le marqueur est dessiné à l'emplacement des données du graphique linéaire. Lorsqu'il y a beaucoup de données, la ligne disparaît avec le marqueur comme la ligne ci-dessous. En spécifiant marquer tous, vous pouvez spécifier le nombre de marqueurs dessinés à intervalles.
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
x = np.linspace(-6,6,1000)
ax.plot(x,norm.pdf(x, loc=0.0, scale=1.0), color='black', linestyle='solid', linewidth = 1.0, marker='o')
ax.plot(x,0.5 + norm.pdf(x, loc=0.0, scale=1.0), color='black', linestyle='solid', linewidth = 1.0, marker='o', markevery = 50)
ax.set_title('4th line plot')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.grid(True)
fig.show()

Typique du marqueur
| marker | description |
|---|---|
| . | point |
| o | circle |
| v | Triangle inférieur |
| ^ | Triangle supérieur |
| s | carré |
| + | plus |
| x | cross |
| * | star |
http://matplotlib.org/api/markers_api.html
Recommended Posts