2011-12-20 92 views
2

如何使用matplotlib繪製這樣的圖形?圖形,即與y軸交叉

graph, that crosses y axis

+0

的thinng,它應該越過Y軸。 Offcourse我可以把它放在那裏作爲另一條線,但所有的y軸數仍然在圖的一側。 – Euphorbium 2011-12-20 21:30:05

回答

1

檢查this examplethis group

例如:

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