文書の過去の版を表示しています。
オブジェクト指向インターフェースでのグラフ作成
グラフ周囲の環境設定
- オブジェクト指向インターフェース
fig = plt.figure(1) ax = fig.add_subplot(111)
plt.figure(): 描画領域を作成fig.add_subplot(): グラフのレイアウトと操作するグラフを指定111: 描画領域を 1 行 1 列として扱い、1 番目のグラフを操作する。- 1 番目の数字: 行数
- 2 番目の数字: 列数
- 3 番目の数字: 操作するグラフ
- 参考サイト: matplotlibの描画の基本 | OpenBook
- 表示範囲の設定
ax.set_xlim(bottom=X_MIN, top=X_MAX) # X の下限と上限の設定 ax.set_ylim(bottom=Y_MIN, top=Y_MAX) # Y の下限と上限の設定
X_MIN: X 軸の下限X_MAX: X 軸の上限Y_MIN: Y 軸の下限Y_MAX: Y 軸の上限
- 表示目盛り幅の設定 (実数)
import matplotlib.ticker as ticker ax.xaxis.set_major_locator(ticker.MultipleLocator(TICK_X)) ax.yaxis.set_major_locator(ticker.MultipleLocator(TICK_Y))
TICK_X: X 軸の目盛り幅TICK_Y: Y 軸の目盛り幅
- 表示目盛り幅の設定 (分割数)
import matplotlib.ticker as ticker ax.xaxis.set_major_locator(ticker.LinearLocator(numticks=N_TICK_X)) ax.yaxis.set_major_locator(ticker.LinearLocator(numticks=N_TICK_Y))
N_TICK_X: X 軸の分割数 (目盛りの数、分割数は N_TICK_X - 1)N_TICK_Y: Y 軸の分割数 (目盛りの数、分割数は N_TICK_Y - 1)