【问题标题】:Python: Why is PillowWriter changing the shape of my gif when I save it?Python:为什么 PillowWriter 在我保存 gif 时会改变它的形状?
【发布时间】:2021-03-05 11:37:57
【问题描述】:

我正在使用 pyplot.pcolor 和 mpl.ArtistAnimation 制作热图动画。它被调整为 1:1 的纵横比,并且边距设置得很紧。动画效果很好,当我在 python 中输出它时,它的裁剪和大小都很好,但是当我使用保存它时

animation=ArtistAnimation(fig1,list_of_figures,interval=400,repeat_delay=2000,blit=True)
f="c:/animations/myanimation.gif"
writergif=mpl.animation.PillowWriter(fps=10)
animation.save(f,writer=writergif)

它可以很好地保存和保持纵横比,但左右间隙很大,好像试图满足一些标准尺寸一样。如何解决这个问题?

【问题讨论】:

  • 动画中的图像是 288 x 288 并且在 python 中输出。但是当我使用 PillowWriter 保存它时,它变为 432 x 288。我完全被难住了。

标签: python python-imaging-library gif


【解决方案1】:

fig.set_size_inches(4.8, 4.8, forward=True)

就在保存之前。

这似乎解决了我的问题。我不知道为什么,因为它不在正确的一端,并且已经设置为这些尺寸。也许它与“forward = True”位有关。我不知道,但它对我有用。

【讨论】:

    猜你喜欢
    • 2018-12-30
    • 2019-05-30
    • 2020-09-02
    • 2014-04-11
    • 2021-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多