gpt4 book ai didi

matplotlib - 我可以在 matplotlib 子图中围绕轴移动吗?

转载 作者:行者123 更新时间:2023-12-03 20:34:01 27 4
gpt4 key购买 nike

一旦我在图中创建了一个子图系统

        fig, ((ax1, ax2)) = plt.subplots(1, 2)

我可以玩转 ax2 的位置吗,例如,将它向右或向左移动一点?

换句话说,在将坐标区对象创建为子图元素后,我可以自定义它在图形中的位置吗?
如果是这样,我该如何编码?

谢谢你的思考

最佳答案

您可以使用命令 get_positionset_position ,如本例所示:

import matplotlib.pyplot as plt

fig, ((ax1, ax2)) = plt.subplots(1, 2)
box = ax1.get_position()
box.x0 = box.x0 + 0.05
box.x1 = box.x1 + 0.05
ax1.set_position(box)
plt.show()

这导致:

Shifting matplotlib subplot

您会注意到我使用属性 x0x1(框的第一个和最后一个 X 坐标)在该轴上移动 0.05 中的绘图。该逻辑也适用于 y。

事实上,如果移位很大并且盒子会重叠(就像这张图片中的 0.2 移位)。

big shift with overlapping plots in matplotlib

关于matplotlib - 我可以在 matplotlib 子图中围绕轴移动吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37241029/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com