0
我想知道是否有可能在matplotlib中有兩個不同的X軸,但不是它們位於圖的兩側。相反,是否可以將它們放在一起?兩個較低的X軸matplot lib
我想知道是否有可能在matplotlib中有兩個不同的X軸,但不是它們位於圖的兩側。相反,是否可以將它們放在一起?兩個較低的X軸matplot lib
這是你要找的嗎?
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())
謝謝,但我怎麼能做到這一點,使X軸是水平相鄰? – modred 2014-10-02 16:46:03
當你說'旁邊'你的意思是'上方和下方'? – farenorth 2014-10-02 16:59:12
如果您提供示例代碼(已完成)並解釋爲什麼它沒有按照您的要求做,我可能會更有幫助。 – farenorth 2014-10-02 17:00:15