matplotlib动画周围的空白

2024-06-09 11:15:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个真正的python新手,似乎不能让这个动画看起来像我想要的那样。我做了一个类似的没有动画的情节,这在Jupyter笔记本中显示得很好,只有很少的空白。然而,当我在情节中添加动画时,它看起来真的很难看!这是我的代码:

%%capture
%matplotlib inline
import matplotlib.animation as animation
plt.rcParams["animation.html"] = "jshtml"

fig = plt.figure(figsize=(11, 9))

# Set map area and set to display coastlines, country borders etc.
ax = plt.axes([0, 0, 0.99, 0.99], projection=ccrs.PlateCarree())
ax.set_extent([-130, -10, 0, 40], ccrs.Geodetic())
ax.background_patch.set_visible(False)
ax.outline_patch.set_visible(True)
ax.add_feature(cfeature.LAND, facecolor='whitesmoke')
ax.coastlines()
ax.add_feature(cfeature.BORDERS)

# selects which data to plot, from larger dataframe
gd = (df_plot.Name == "IRMA")
Long_vals = df_plot.loc[gd,'Long'].values
Lat_vals = df_plot.loc[gd,'Lat'].values
data = np.array([Long_vals,Lat_vals])

# set up empty plot
l, = ax.plot([], [], c='red')

# define how to add points to plot in animation
def update_track(num, data, line):
    line.set_data(data[..., :num])
    return line,

anim = animation.FuncAnimation(fig, update_track, fargs=(data, l),
                               frames=60, interval=50, 
                               blit=True, repeat=False)

现在,我的情节的底部是这样的。。。在顶部和侧面有相似数量的空白。我能把它放在笔记本的其他地方吗?谢谢。在

enter image description here


Tags: toadddfdataplot动画pltax