如何使四个Y轴/刺正确绘制?

时间:2020-05-02 17:28:18

标签: matplotlib

我无法像预期的那样工作。刺/文本总是放错位置:

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.1, left=0.2, right=0.8, top=0.9)

par1 = host.twinx()
par2 = host.twinx()
par3 = host.twinx()
par3.axis["right"].set_visible(False)

new_fixed_axis = par2.get_grid_helper().new_fixed_axis
par2.axis["right"] = new_fixed_axis(loc="right",axes=par2,offset=(60, 0))

host.set_xlabel("Y axis")
host.set_ylabel("X axis 1 on the left")
par1.set_ylabel("X axis 2 on the right")
par2.set_ylabel("X axis 3 on the right")
par3.set_ylabel("X axis 4 on the left")


new_fixed_axis = par3.get_grid_helper().new_fixed_axis
par3.axis["left"] = new_fixed_axis(loc="left",axes=par3,offset=(-60, 0))


p1, = host.plot([1,2,3,4],[1,2,3,4], label="1")
p2, = par1.plot([1,2,3,4],[2,2,2,2], label="2")
p3, = par2.plot([1,2,3,4],[3,3,2,1], label="3")
p4, = par3.plot([1,2,3,4],[1,1,2.5,3.5], label="4")

plt.show()

Stackoverflow要求我写更多的文章,因为大多数文章都是代码,因此这里有更多文本可以满足要求,而开头的内容可以解决所有问题。

0 个答案:

没有答案
相关问题