Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何正确重置带有移动点的动画地图上的文字_Python_Matplotlib_Animation_Geopandas - Fatal编程技术网

Python 如何正确重置带有移动点的动画地图上的文字

Python 如何正确重置带有移动点的动画地图上的文字,python,matplotlib,animation,geopandas,Python,Matplotlib,Animation,Geopandas,我正在尝试为国际空间站制作一个实时跟踪器。我用红色标记绘制了背景地图和国际空间站的位置。我目前正在尝试让这个职位进行实时更新/动画制作 为此,我在动画循环中使用“plt.cla()”清除了该图形,但这也清除了背景贴图 那么,当地图上的点和文本更新时,我如何保持背景呢 plt.interactive(False) index = count() locator = Nominatim(user_agent='openmapquest') world = gpd.read_file(gpd.dat

我正在尝试为国际空间站制作一个实时跟踪器。我用红色标记绘制了背景地图和国际空间站的位置。我目前正在尝试让这个职位进行实时更新/动画制作

为此,我在动画循环中使用“plt.cla()”清除了该图形,但这也清除了背景贴图

那么,当地图上的点和文本更新时,我如何保持背景呢

plt.interactive(False)
index = count()

locator = Nominatim(user_agent='openmapquest')
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

def getCord():
    req = ur.Request("http://api.open-notify.org/iss-now.json")
    response = ur.urlopen(req)
    obj = json.loads(response.read())
    issLat = obj['iss_position']['latitude']
    issLon = obj['iss_position']['longitude']
    df = pd.DataFrame({'Name': ['ISS'], 'Latitude': [issLat], 'Longitude': [issLon]})
    return df

fig = world.plot(color='white', edgecolor='black')

def animate(i):
    plt.cla()
    df = getCord()
    gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.Longitude,df.Latitude))
    gdf.plot(ax=fig,color='red')
    coordinates = (df.Latitude + ', ' + df.Longitude)
    location = locator.reverse(coordinates)
    figText = 'Nearest Address: N/a'
    if location is not None:
        figText = 'Nearest Address:  ' + location.address

    now = datetime.now()
    current_time = now.strftime("%H:%M:%S")
    fig.text(0.1, 0.1, figText, fontsize=10, transform=plt.gcf().transFigure, color = 'red')
    fig.text(0.8, 0.8, 'Time:'+current_time, fontsize=10, transform=plt.gcf().transFigure, color='red')

ani = FuncAnimation(plt.gcf(), animate,interval=1000)
plt.tight_layout()
plt.show()
如果没有clear语句,文本将在旧文本的顶部设置动画

使用clear语句,将删除贴图并重置轴

请回答问题,包括所有导入内容以及运行代码所需的任何内容。