matplotlib动画周围的白色空间

时间:2018-06-02 16:12:42

标签: python animation matplotlib plot jupyter-notebook

我是一个真正的蟒蛇新手,似乎无法让这个动画看起来我想要的。我制作了一个没有动画的类似情节,这在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

0 个答案:

没有答案