我不经常绘制国际空间站的位置。在互联网上找到一些代码。为python 3.5.1更改了它。 当它在while循环中运行时,它只显示一个白色屏幕。 在没有while循环的情况下运行它并删除最后两行代码,它在世界地图上显示ISS!
要改变它以使其正常工作。 尝试在Macbook上运行它。
""" plot the ISS and update every 60 seconds"""
import numpy as np
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from datetime import datetime
import time
import urllib.request
import json
def getiss():
""" call opennotify api"""
print('Get ISS data')
r=urllib.request.urlopen('http://api.open-notify.org/iss-now.json',timeout=4)
mydata = json.loads(r.read().decode(r.info().get_param('charset') or 'utf-8'))
return(mydata)
while True:
iss = getiss()
lat = iss['iss_position']['latitude']
lon = iss['iss_position']['longitude']
# miller projection
map = Basemap(projection='mill',lon_0=0)
# plot coastlines, draw label meridians and parallels.
map.drawcoastlines()
map.drawparallels(np.arange(-90,90,30),labels=[1,0,0,0])
map.drawmeridians(np.arange(map.lonmin,map.lonmax+30,60),labels=[0,0,0,1])
# fill continents 'coral' (with zorder=0), color wet areas 'aqua'
map.drawmapboundary(fill_color='aqua')
map.fillcontinents(color='coral',lake_color='aqua')
# shade the night areas, with alpha transparency so the
# map shows through. Use current time in UTC.
date = datetime.now()
CS=map.nightshade(date)
plt.title('ISS Location For for %s Lat: %.2f Long: %.2f' % (date.strftime("%d %b %Y %H:%M:%S"),lat,lon))
x,y = map(lon, lat)
map.plot(x, y, 'bo', markersize=12)
plt.ion()
plt.draw()
plt.show()
time.sleep(60)
plt.clf()