所需模块
numpy
pylab
matplotlib
mpl_toolkits
效果
代码
# -*- coding: utf-8 -*-
"""
@author: Persues
"""
from pylab import *
import numpy as np
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from matplotlib import animation
### 白色底 黑灰色
## 画地球
fig = plt.figure(figsize=(8,8),dpi=300)
ax = plt.subplot()
earth=Basemap(projection="ortho",lat_0=30,lon_0=0)
#earth=Basemap()
## 画海岸线
earth.drawcoastlines(linewidth=0.5)
## 画国家
earth.drawcountries(linewidth=0.5)
## 画地球的基色
earth.drawmapboundary(fill_color="w")
## 画陆地的颜色 画江河湖泊的颜色
earth.fillcontinents(color="silver", lake_color="w")
##设置初始的图画
def init():
earth=Basemap(projection="ortho",lat_0=30,lon_0=0)
#earth=Basemap()
## 画海岸线
earth.drawcoastlines(linewidth=0.5)
## 画国家
earth.drawcountries(linewidth=0.5)
## 画地球的基色
earth.drawmapboundary(fill_color="w")
## 画陆地的颜色 画江河湖泊的颜色
earth.fillcontinents(color="silver", lake_color="w")
## 建立地球不同位置和时间t的关系函数
def get_earth(t):
## 建立地球 选择投影为球 投影中间坐标的经纬度
tk = float(t)
ax.clear()
earth=Basemap(projection="ortho",lat_0=30,lon_0=tk)
#earth=Basemap()
## 画海岸线
earth.drawcoastlines(linewidth=0.5)
## 画国家
earth.drawcountries(linewidth=0.5)
## 画地球的基色
earth.drawmapboundary(fill_color="w")
## 画陆地的颜色 画江河湖泊的颜色
earth.fillcontinents(color="silver", lake_color="w")
#return earth
## 建立动画
ani = animation.FuncAnimation(fig,get_earth,frames=np.arange(0,360,1),interval = 50, init_func=init)
ani.save('spin_earth.gif', writer='imagemagick',dpi=300, fps=30)
plt.show()