python代码 旋转的地球

python代码 旋转的地球

所需模块

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()

  • 0
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Persus

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值