ast*_*son 6 python plot animation matplotlib jupyter-notebook
我是一个真正的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)
Run Code Online (Sandbox Code Playgroud)
目前,我的图的底部看起来像这样......顶部和侧面有类似数量的空白。我可以让它与笔记本的其他部分更加齐平吗?谢谢。
| 归档时间: |
|
| 查看次数: |
591 次 |
| 最近记录: |