【问题标题】:Pyplot animation inserts large paddingPyplot 动画插入大填充
【发布时间】:2021-09-06 19:25:16
【问题描述】:
fig = plt.figure()
fig.add_subplot(2, 2, 1)
fig.add_subplot(2, 2, 2)
fig.add_subplot(3, 2, (3, 4))

按预期绘制

但是动画

import matplotlib.animation as animation

class Animation(animation.TimedAnimation):
    def __init__(self):
        fig = plt.figure()
        fig.add_subplot(2, 2, 1)
        fig.add_subplot(2, 2, 2)
        fig.add_subplot(3, 2, (3, 4))
        animation.TimedAnimation.__init__(self, fig, blit=True)

    def _draw_frame(self, frame_idx): pass

    def new_frame_seq(self): return iter(range(2))

ani = Animation()
ani.save('test.mp4')

插入很多填充

这可以通过fig.subplots_adjust(left=0, right=1, bottom=-.5, top=1) 进行补救(注意是否定的bottom),但它会改变最初预期的比例。此外,动画结尾处的plt.show() 与直接绘图相同(没有subplots_adjust),但它只是最后一帧。

如何使animation 填充与直接绘图相同,或者以其他方式删除此填充? matplotlib 3.4.3,Windows 10

【问题讨论】:

    标签: python matplotlib matplotlib-animation


    【解决方案1】:

    可以通过figsize降低高度,通过topbottom来回校准。但这不应该是必需的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-04
      • 1970-01-01
      • 2017-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-09
      相关资源
      最近更新 更多