简体   繁体   English

如何使用 matplotlib 创建其帧共享常用颜色条的 GIF?

[英]How can I use matplotlib to create a GIF whose frames share a commonly-scaled colorbar?

I want to make a GIF animation of a wave propagation.我想做一个波传播的 GIF animation。 My problem is the following: the colorbar should be constant for all the frames.我的问题如下:所有帧的颜色条都应该是恒定的。 How to make sure that the scale of the solution can be maintained from one frame to another, for the sake of readability?为了可读性,如何确保解决方案的规模可以从一帧到另一帧保持不变?

Here is my code:这是我的代码:

fig = plt.figure(figsize=(7,7))
fig = dolfin.plot(u)

plt.title(r'$u(\mathbf{x}, t)$')
plt.xlabel(r'$x$ [m]')
plt.ylabel(r'$y$ [m]')
plt.colorbar(fig, fraction=0.058, pad=0.04)
plt.savefig('fig'+str(n)+'.png',bbox_inches='tight', dpi=150)
plt.close()

As per my comments, you should just be able to add plt.clim(vmin,vmax) , or fig.set_clim(vmin,vmax) , as necessary.根据我的评论,您应该可以根据需要添加plt.clim(vmin,vmax)fig.set_clim(vmin,vmax)

Reference: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.clim.html参考: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.clim.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM