はじめに
こんにちは.
クリスマス?何それおいしいの?
実験するより,実験データの処理をするコードを書くこと自体の方が好きな,はんぺんです.
Pythonでグラフを表示するのはいいけど細かいところ直す方法が分からなくなってしまうことが多いので,この記事はメモとして共有していこうと思います.
データの生成
1 2 3 4 |
x = np.arange(0,10) y_1 = np.arange(0,10) y_2 = np.array([i**2 for i in range(10)]) y_3 = np.array([np.e**i for i in range(10)]) |
グラフの表示
基本形
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
fig = plt.figure(figsize=(9,6)) #図の生成 ax = fig.add_subplot(1,1,1) #軸の指定 plt.rcParams["font.size"] = 24 #フォントサイズの指定 ax.plot(x, y_1, label='$\ y=x $') #データのプロット ax.set_xlim([None, None]) #x軸の範囲 ax.set_ylim([None, None]) #y軸の範囲 ax.set_title('Graph',fontsize=24) #グラフのタイトル ax.set_xlabel('x') #x軸の名前 ax.set_ylabel('y') #y軸の名前 ax.legend(loc='upper left', fontsize=20) #凡例の表示 plt.show() #グラフの表示 |

対数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
fig = plt.figure(figsize=(9,6)) #図の生成 ax = fig.add_subplot(1,1,1) #軸の指定 plt.rcParams["font.size"] = 24 #フォントサイズの指定 ax.plot(x, y_3, label='$\ y=e^{x} $') #データのプロット ax.set_yscale('log') #対数 ax.set_xlim([None, None]) #x軸の範囲 ax.set_ylim([None, None]) #y軸の範囲 ax.set_title('Graph',fontsize=24) #グラフのタイトル ax.set_xlabel('x') #x軸の名前 ax.set_ylabel('y') #y軸の名前 ax.legend(loc='upper left', fontsize=20) #凡例の表示 plt.show() #グラフの表示 |

まとめ
随時更新していきます.
コメントを残す