Python: Ось исчезает на рисунке при анимации с целлулоидом - PullRequest
0 голосов
/ 07 марта 2020

Я использую целлулоид (https://github.com/jwkvam/celluloid), чтобы нарисовать функцию в течение нескольких лет, и я люблю ее до сих пор, она прекрасно работает! У меня есть одна небольшая проблема, однако края моего графика исчезают после первого l oop. Я приложил изображения того, как это выглядит.

Первый л oop:

First_loop

Второй л oop:

Second_loop

Как видите, ось исчезла. Я использую cartopy и matplotlib в блокноте jupyter, и это мой код для анимации:

# 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())

Есть ли способ сделать так, чтобы края появлялись на протяжении всей анимации? Даже у пользователей, у которых нет опыта работы с целлулоидом, была ли у вас эта проблема с исчезновением оси, и если да, то как вы ее исправили?

...