LoginSignup
16
24

More than 5 years have passed since last update.

[Pythonによる科学・技術計算] 対数グラフ,可視化,matplotlib

Last updated at Posted at 2017-07-20

matplotlibのset_xscale とset_yscaleに'log'を指定することで片対数および両対数グラフを描くことができる。
例として $ y = e^{2x+1}$をプロットする。




import numpy as np
import matplotlib.pyplot as plt
"""
対数グラフ
"""

x = np.arange(0.001, 10, 0.1)

y = np.exp(2*x+1) # プロットする関数

plt.plot(x, y)

ax = plt.gca()
ax.spines['top'].set_color('none')

##
ax.set_yscale('log')  # メイン: y軸をlogスケールで描く
#ax.set_xscale('log')
##
plt.title('single logarithmic plot') 
plt.xlabel('X',fontsize=18)
plt.ylabel('Y',fontsize=18)

plt.grid(which="both") # グリッド表示。"both"はxy軸両方にグリッドを描く。

plt.show()

結果(1):片対数グラフ

t.png

結果(2):両対数グラフ

以下のように,x軸もlogスケールに指定することで両対数グラフを描くことができる。

ax.set_yscale('log')  # y軸をlogスケールで描く
ax.set_xscale('log')  # x軸をlogスケールで描く

tt.png

16
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
24