我有一系列的子批次,我希望它们在除了2个子批次之外的所有子批次中共享x和y轴(以每行为基础)。在
我知道可以单独创建所有子批次,然后add the ^{
但是,这是一个非常多的代码,因为我必须对大多数子批执行此操作。在
一种更有效的方法是创建具有所需sharex
/sharey
属性的所有子批次,例如:
import matplotlib.pyplot as plt
fix, axs = plt.subplots(2, 10, sharex='row', sharey='row', squeeze=False)
然后设置取消设置sharex
/sharey
功能,假设的工作方式如下:
上面的方法不起作用,但是有什么方法可以得到它吗?在
正如@zan在their answer中指出的那样,您可以使用
ax.get_shared_x_axes()
获得一个Grouper
对象,它包含所有链接的轴,然后.remove
来自这个分组程序的任何轴。问题是(正如@WMiller指出的那样),对于所有轴,股票行情器仍然是相同的。在所以你需要
完整示例
注意,在上面我只改变了x轴的记号,也只改变了主刻度。如果需要的话,对y轴和小记号也需要执行相同的操作。在
您可以使用
ax.get_shared_x_axes()
或属性ax._shared_y_axes
访问共享轴组。然后可以使用xaxis.set_tick_params(which='both', labelleft=True)
或使用setp(ax, get_xticklabels(), visible=True)
重置标签的可见性,但是这两种方法都有一个固有的问题:记号格式化程序仍然在轴之间共享。据我所知,这是没有办法的。下面是一个示例来演示:您可以使用
ax.get_shared_x_axes()
获取包含所有链接轴的Grouper对象。然后使用group.remove(ax)
从该组中删除指定的轴。您还可以group.join(ax1, ax2)
添加新共享。在这仍然需要一些调整来设置记号,但是右下角的绘图现在有了自己的限制。
相关问题 更多 >
编程相关推荐