python - python - 在主 x 轴旁边制作一个附加(寄生轴)
问题描述
我正在使用下面的示例,该示例显示了 y 轴旁边的附加轴的构造。 https://matplotlib.org/2.0.2/examples/axes_grid/demo_parasite_axes2.html
我想知道的是如何修改代码以在主 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()
推荐阅读
- javascript - Onclick Word Replacement 无法与 PHP 一起正常工作
- bash - 如何在 Bash 中的 heredoc 之后设置参数
- python - 在python中的循环内调用一系列具有相同名称的变量
- laravel - Laravel Passport 返回所有用户
- java - 无法弄清楚如何为响铃创建取消按钮
- python - 单击html按钮时如何调用python函数并传递参数?
- redisgraph - 目前是否可以在 redis-graph 中进行匹配交集查询?
- html - Woocommerce 产品选项 - 突出显示所选选项
- android - 带有 Glide 的 ImageSwitcher
- c# - 映射到模型