Python: Axis disappearing in figure when animating with celluloid

廉价感情. 提交于 2021-01-29 08:57:39

问题


I am using celluloid (https://github.com/jwkvam/celluloid) to plot a function over several years and i love it so far, it works great! I have one small problem though, the edges of my plot disappear after the first loop. I have attached images of how this looks.

First loop:

Second loop:

As you can see the axis has disappeared. I am using cartopy and matplotlib in jupyter notebook and this is my code for the animation:

# Use 'Agg' so script only displays animation in HTML
import matplotlib
matplotlib.use('Agg')
from IPython.display import HTML
# Use celluloid as this is a way easier method to animate than matplotlib
from celluloid import Camera

# Sets up the map plot with coastlines from cartopy and the PlateCarree projection
# The PlateCarree projection is neither equal area nor conformal, thus it is mostly used for thematic 
mapping
fig=plt.figure(figsize=(9,5))
cmap=matplotlib.cm.RdBu_r 
norm=matplotlib.colors.Normalize(vmin=0, vmax=50)
ax=plt.axes(projection=ccrs.PlateCarree(),extent=[-180, 180, -90, 90])
# Set labels and ticks for x- and y-axis
ax.set_xticks([-180, -120, -60, 0, 60, 120, 180], crs=ccrs.PlateCarree())
ax.set_yticks([-90, -60, -30, 0, 30, 60, 90], crs=ccrs.PlateCarree())
plt.xlabel('Longitude [deg]')
plt.ylabel('Latitude [deg]')

# Defines camera and executes plot every year in chosen time range
camera = Camera(fig)
for i in range(0,(stop-start)+1):
    plt.scatter(nphi[i], nthe[i], c=mag[i], s=40, norm=norm, cmap=cmap, edgecolor="k")
    ax.text(0, 1.05, 'Global Observatory Plot of SV magnitude from target year ' 
             + str(start+i) + ' in the dB_' + out + '-direction', fontsize=9, transform=ax.transAxes)
    ax.coastlines()
    camera.snap()

# Sets up colourbar and set a label
cbar=plt.colorbar()
cbar.set_label('Magnitude of SV [nT/yr$^2$]')

# Create animation with slower interval between plots, saves the animation, and displays it as HTML video
animation = camera.animate(interval=800)
animation.save('Figures/GlobalSVMag.mp4')
HTML(animation.to_html5_video())

Is there a way to make the edge appear all the way through the animation? Even for users who don't have experience with celluloid, have you had this issue with the axis disappearing, and if so, how did you fix it?

来源:https://stackoverflow.com/questions/60573387/python-axis-disappearing-in-figure-when-animating-with-celluloid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!