この記事では、Matplotlib の plot() 関数 plot() パラメータの使い方について詳しく説明します。
折れ線グラフは、方程式 y=ax+b における y と x の関係のような、2 つの変数の関係を表すのに使われます;
折れ線グラフをプロットするための Matplotlib 関数はplot()です.
plot()一般的なパラメータの使用法
import math
import matplotlib.pyplot as plt
plt.figure(dpi=120)
plt.plot(range(2,10),#x軸方向変数
[math.sin(i) for i in range(2,10)],#y軸方向変数
linestyle='--',#
linewidth=2,#
color='red',#ラインカラーとマーカーカラーは、markeredgecolor markerfacecolorに設定がある場合、ラインカラーをコントロールするだけでよい。
##markerの機能セット
marker='^',#marker形状
markersize='15',#marker
markeredgecolor='green',#markerフレームの色
markeredgewidth=2, #marker外枠の幅
markerfacecolor='red',#marker
fillstyle='top',#marker記入フォーム、任意{'full', 'left', 'right', 'bottom', 'top', 'none'}
markerfacecoloralt='blue',#marker未塗装部分の色
markevery=2,#1本おきにマーカーを引く
label='sin(x)',#
alpha=0.3,#ラインとマーカーの透明度
)
##以下の2本の線は、デフォルトのパラメーターを使用して描かれている。
plt.plot(range(2,10),[math.cos(i) for i in range(2,10)],label='cos(x)')
plt.plot(range(2,10),[2*math.cos(i)+1 for i in range(2,10)],label='2*cos(x)+1')
plt.legend()#作図例
plt.xlabel('x')
plt.ylabel('f(x)')
ご覧ください。
パブリック・ナンバーへようこそ:ピトニック・バイオロジカル・ピープル