#以下是我的代码,应该是animate部分的循环有问题,在地图上动不了
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import xlrd
from matplotlib import cm
from matplotlib import animation
plt.figure(figsize = (16, 8))
map = Basemap()
map.drawcoastlines()
map.drawmapboundary()
map.drawcountries(linewidth = 1.5)
dataset = xlrd.open_workbook("/Users/apple/Desktop/indicator GDP.xlsx")
sheet = dataset.sheet_by_index(0)
gdp = sheet.col_values(3)
lon = sheet.col_values(2)
lat = sheet.col_values(1)
size=(gdp/np.max(gdp))*1000
x,y = map(lon, lat)
map.scatter(x, y, s = size)
def animate(i):
gdp = sheet.col_values(3 + i)
size=(gdp/np.max(gdp))*1000
x,y = map(lon, lat)
map.scatter(x, y, s = size)
return map.scatter(x, y, s = size)
def init(i):
gdp = sheet.col_values(3)
size=(gdp/np.max(gdp))*1000
x,y = map(lon, lat)
map.scatter(x, y, s = size)
return map.scatter(x, y, s = size)
ani = animation.FuncAnimation(fig = fig, func = animate,
frames = 100, init_func = init, interval = 20, blit = False)
plt.show()