【问题标题】:Can I move about the axes in a matplotilb subplot?我可以在 matplotlib 子图中移动轴吗?
【发布时间】:2016-09-11 11:34:16
【问题描述】:

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

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

我可以调整ax2 的位置吗,例如,将其向右或向左移动一点?

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

感谢您的考虑

【问题讨论】:

    标签: matplotlib axes subplot


    【解决方案1】:

    您可以使用命令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()
    

    结果如下:

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

    事实上,如果偏移太大,框会重叠(就像这张图片中的偏移为0.2)。

    【讨论】:

    • 是否有 fig = plt.figure() 而不是 fig, ax = plt.subplots() 的等价物?
    猜你喜欢
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 2013-01-02
    • 2017-01-01
    相关资源
    最近更新 更多