Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python-在主x轴旁边制作一个附加(寄生轴)_Python_Matplotlib - Fatal编程技术网

python-在主x轴旁边制作一个附加(寄生轴)

python-在主x轴旁边制作一个附加(寄生轴),python,matplotlib,Python,Matplotlib,我正在使用下面的示例,该示例显示了y轴旁边的附加轴的构造。 我想知道的是如何修改代码以在主x轴旁边的底部获得另一个寄生虫轴,使其直接绑定到主y轴。我已在中编辑了示例以实现您的目标。这是通过调整y轴的偏移位置和范围来实现的。这符合你问题的意图吗 from mpl_toolkits.axes_grid1 import host_subplot from mpl_toolkits import axisartist import matplotlib.pyplot as plt host = h

我正在使用下面的示例,该示例显示了y轴旁边的附加轴的构造。


我想知道的是如何修改代码以在主x轴旁边的底部获得另一个寄生虫轴,使其直接绑定到主y轴。

我已在中编辑了示例以实现您的目标。这是通过调整y轴的偏移位置和范围来实现的。这符合你问题的意图吗

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

host = host_subplot(111, axes_class=axisartist.Axes)
plt.subplots_adjust(right=0.75)

par1 = host.twiny()
par2 = host.twiny()

par2.axis["bottom"] = par2.new_fixed_axis(loc="bottom", offset=(0, 25))

par1.axis["top"].toggle(all=True)
par2.axis["bottom"].toggle(all=True)

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

host.set_ylim(-0.25, 2)
host.set_xlim(0, 2)
par1.set_xlim(0, 4)
par2.set_xlim(1, 65)

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

host.legend()

host.axis["bottom"].label.set_color(p1.get_color())
par1.axis["top"].label.set_color(p2.get_color())
par2.axis["bottom"].label.set_color(p3.get_color())

plt.show()

谢谢@r-初学者,我想在参考示例中所示的主y轴旁边的现有寄生虫轴的基础上,在主x轴下方增加一个寄生虫轴。简言之,将有两个寄生虫轴。这可能吗?我认为可以将我在回答中修改的代码部分添加到示例中给出的示例中。