简体   繁体   中英

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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