2010-11-27 38 views
9

パイロットプロットの軸設定をどのように制御するのですか?私は単に matplotlibの軸設定を変更する

pylab.plot(*self.plot_generator(low, high)) 

    pylab.show() 

を行っていると私は

alt text

を望むものであるこれを取得するが、私は、x軸は0ではなく、一番下になりたいです。どうすればいい? 0とy軸の開始を設定する

pylab.xlim(xmin=0) 

pylab.ylim(ymin=0) 

これらのいずれかを入れて0にx軸の開始を設定する

答えて

14
# create some data 
x = np.linspace(-np.pi,np.pi,100) 
y = np.cos(2.5*x) 

fig = plt.figure() 
ax = fig.add_subplot(111) 
ax.plot(x,y, mfc='orange', mec='orange', marker='.') 

# using 'spines', new in Matplotlib 1.0 
ax.spines['left'].set_position('zero') 
ax.spines['right'].set_color('none') 
ax.spines['bottom'].set_position('zero') 
ax.spines['top'].set_color('none') 
ax.spines['left'].set_smart_bounds(True) 
ax.spines['bottom'].set_smart_bounds(True) 
ax.xaxis.set_ticks_position('bottom') 
ax.yaxis.set_ticks_position('left') 

ax.axhline(linewidth=2, color='blue') 
ax.axvline(linewidth=2, color='blue') 
show() 

alt text

+0

これは、あなたがここにその点で棘を使用する方法の詳細一般的な説明を見つけることができます@Joeキングトンさんのコメント – Falmarri

+0

と一緒に、私は必要なもののように見えます.html –

+2

ここで 'ax.spines'がなぜ使われるのか説明できますか? AFAIKでは、すべてのメソッド 'set_position'または' set_color'は 'matplotlib.spines.Spine'クラスオブジェクトのメンバです。それは混乱している。 – haccks

10

あなたが好きな場合は、pylab.plotコールの後に電話をかけてください。

1

私はこれが何をしたい

alt text

あるしかし、私のコードは非常に汚れていると思います。それは慎重に調整しなければならない。 gridを直接お使いになるのはなぜですか? http://matplotlib.org/examples/pylab_examples/spine_placement_demo:

import pylab 
import numpy as np 

x = np.arange(20)+300 
y = x - 308 

x1 = x[y>=0] 
x2 = x[y<=0] 
y1 = y[y>=0] 
y2 = y[y<=0] 


fig = pylab.figure() 
fig.subplots_adjust(hspace=0.00001) 
bx = pylab.subplot(212) 
pylab.ylim(-12,0) 
pylab.plot(x2,y2) 
pylab.setp(bx.get_xticklabels(), visible=False) 
ax = pylab.subplot(211,sharex=bx) 
pylab.plot(x1,y1) 
pylab.ylim(0,12) 
pylab.setp(ax.get_xticklabels(), visible=True) 
pylab.show() 
+2

スパインを使用する方がはるかに簡単です。この例を参照してください:http://matplotlib.sourceforge.net/examples/pylab_examples/spine_placement_demo.html#pylab-examples-spine-placement-demo –

関連する問題