グラフを書くときの軸の設定です。
プロット範囲をmatplotlibに任せるには、'auto'、'equal'、'tight'、'scaled'のどれかを引数にして、axis関数を呼び出します。
xticks,yticksを使えば、座標軸に文字列を使ったり、グリッドの間隔を指定できます。
サンプル画像
ソースファイル
# -*- coding: utf-8 -*- from pylab import * R = 1.2 A = 1.2 I1 = arange(0,2*pi,0.01) I2 = arange(0,4*pi,0.01) axis_options = ['auto', 'equal', 'tight', 'scaled'] def plot_circle(n): opt = axis_options[n] subplot(2,2,n) title(opt) plot(A * sin(I1)*R, cos(I1)*R) axis(opt) def main(): figure() # 軸のスケール for i in range(len(axis_options)): plot_circle(i) savefig('axis1.png') show() # 目盛り subplot(2,1,1) title('default') plot (sin(I2)*R, cos(0.5*I2)*R) grid(True) # gridを入れる。 subplot(2,1,2) title('axis example') xticks([-1, 0, 1] ,('Negative', 'Neutral', 'Positive')) # 軸に文字列を使う yticks(arange(-1.5, 2.0, 1)) plot (sin(I2)*R, cos(0.5*I2)*R) [xmin, xmax, ymin, ymax] = axis() #今の境界を返す axis([xmin-1.0,xmax+1.0,ymin-0.5,ymax+0.5]) #新しい境界を設定 grid(True) # gridを入れる。 savefig('axis2.png') show() if __name__ == "__main__": main()
axis1.png