2014-10-02 63 views

回答

2

這是你要找的嗎?

Two x-axes on the bottom.

from mpl_toolkits.axes_grid1 import host_subplot 
import mpl_toolkits.axisartist as AA 
import matplotlib.pyplot as plt 


host = host_subplot(111, axes_class=AA.Axes) 
plt.subplots_adjust(bottom=0.2) 

par2 = host.twiny() 

offset = -40 
new_fixed_axis = par2.get_grid_helper().new_fixed_axis 
par2.axis["bottom"] = new_fixed_axis(loc="bottom", 
            axes=par2, 
            offset=(0, offset)) 

par2.axis["top"].toggle(all=False) 

host.set_xlim(0, 2) 
host.set_ylim(0, 2) 

host.set_ylabel("Distance") 
host.set_xlabel("Density") 
par2.set_xlabel("Velocity") 

p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density") 
p3, = par2.plot([50, 30, 15], [0, 1, 2], label="Velocity") 

par2.set_xlim(1, 65) 

host.legend() 

host.axis["bottom"].label.set_color(p1.get_color()) 
par2.axis["bottom"].label.set_color(p3.get_color()) 
+0

謝謝,但我怎麼能做到這一點,使X軸是水平相鄰? – modred 2014-10-02 16:46:03

+0

當你說'旁邊'你的意思是'上方和下方'? – farenorth 2014-10-02 16:59:12

+0

如果您提供示例代碼(已完成)並解釋爲什麼它沒有按照您的要求做,我可能會更有幫助。 – farenorth 2014-10-02 17:00:15

相關問題