2011-12-20 21 views
2

matplotlibを使ってどのようにグラフを描くことができますか?y軸を横切るグラフ

graph, that crosses y axis

+0

がY軸と交差する必要があることthinng、。 Offcourse私はそこにもう一つの行として配置することができますが、すべてのy軸の数字はまだグラフの横にあります。 – Euphorbium

答えて

1

例えばthis group

からチェックthis example:あなたの写真へ

from matplotlib import pyplot as plt 
import numpy as np 

def line(x, slope=1, zero=0): 
    return zero + slope * x 

x = np.array([-4,10]) 
y1 = line(x, 2, 2) 
y2 = line(x, 1, 3) 

fig = plt.figure() 
ax = fig.add_subplot(111) 
ax.plot(x,y1) 
ax.plot(x,y2) 

ax.spines['left'].set_position(('data', 0)) 
ax.spines['right'].set_color('none') 
ax.spines['bottom'].set_position(('data',0)) 
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') 

plt.show() 

enter image description here

または近い(ここで私はset_smart_boundsを排除win7のに効果があることがないようですので、例):

ax.spines['left'].set_position(('data', 0)) 
ax.spines['right'].set_color('none') 
ax.spines['bottom'].set_position(('data',0)) 
ax.spines['top'].set_color('none') 
ax.xaxis.set_ticks_position('bottom') 
ax.yaxis.set_ticks_position('left') 
plt.ylim(ymin=0) 
plt.show() 

enter image description here

関連する問題