python - 使用 Smopy 在 Matplotlib 动画中添加额外图形

标签 python animation matplotlib

我正在尝试在 jupyter 中使用 smopy 和 matplotlib 创建动画 map ,但是当我运行代码时,我得到两个数字而不是一个。第一个图显示在 map 上方并且是空的。谁能告诉我如何解决这个问题,以便只绘制动画?

import smopy
import matplotlib.animation as animation

n= 1000
%matplotlib notebook

def update(curr):
    if curr == n-100:
        a.event_source.stop()
    lons = crime_df.X[curr:curr+100]
    lats = crime_df.Y[curr:curr+100]
    x,y = map.to_pixels(lats,lons)
    ax.scatter(x, y, c='r', alpha=0.7, s=200)
    plt.title(curr)

fig = plt.figure()
ax = smopy.Map((37.6624,-122.5168,37.8231,-122.3589), z=12)
ax = ax.show_mpl(figsize=(8,8))
a = animation.FuncAnimation(fig, update, interval=100)

最佳答案

如果不符合要求,则不应创建额外的图形:省略 plt.figure()

import smopy
import matplotlib.pyplot as plt
import matplotlib.animation as animation

n= 1000
%matplotlib notebook

def update(curr):
    if curr == n-100:
        a.event_source.stop()
    lons = crime_df.X[curr:curr+100]
    lats = crime_df.Y[curr:curr+100]
    x,y = map.to_pixels(lats,lons)
    ax.scatter(x, y, c='r', alpha=0.7, s=200)
    plt.title(curr)


m = smopy.Map((37.6624,-122.5168,37.8231,-122.3589), z=12)
ax = m.show_mpl(figsize=(8,8))
a = animation.FuncAnimation(ax.figure, update, interval=100)

或者预先创建图形,

fig, ax = plt.subplots(figsize=(8,8))
m = smopy.Map((37.6624,-122.5168,37.8231,-122.3589), z=12)
m.show_mpl(ax = ax)
a = animation.FuncAnimation(fig, update, interval=100)

关于python - 使用 Smopy 在 Matplotlib 动画中添加额外图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48847472/

相关文章:

python - 导入错误 : The Python Imaging Library (PIL) is required to load data from jpeg files

python - 玛雅Python : rename duplicated joint children

Python 元组列表 : organize by unique elements to a dictionary

python - 使用在 python 中加权的元素制作六角形图

python - Django - 每个模板中的通用数据

html - 从中心出现关键帧动画

javascript - jquery if语句动画返回

jquery - 无限背景位置动画 - jQuery

python - 带有 Pandas 时间戳的 Matplotlib 条形图

python - 直方图未显示在 f 分布图中