我尝试(在python 3.6中)根据纬度和经度坐标从全局地图上的数据库(sqlite和底图模块)绘制点(机场)。但是,我的代码将点作为一个单独的数字绘制在地图上,并且运行时错误说明: RuntimeError:不能将单个艺术家放在多个图中。我不确定我做错了什么:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import sqlite3
conn = sqlite3.connect("flights.db")
cur = conn.cursor()
cur.execute("select * from airlines limit 5;")
results = cur.fetchall()
print(results)
coords = cur.execute(""" select cast(longitude as float), \
cast(latitude as float) from airports;""" \
).fetchall()
m = Basemap(projection = 'merc', llcrnrlat =-80, urcrnrlat = 80, \
llcrnrlon = -180, urcrnrlon = 180, lat_ts = 20, \
resolution = 'c')
m.drawcoastlines()
m.drawmapboundary()
x, y = m([l[0] for l in coords], [l[1] for l in coords])
m.scatter(x, y, 1, marker='o', color='red')
我得到的错误如下:
RuntimeError: Can not put single artist in more than one figure