2
我嘗試根據經度和緯度座標從全局地圖上的數據庫(sqlite和底圖模塊)繪製(在python 3.6中)繪製點(機場)。但是,我的代碼將這些點繪製爲與地圖分開的圖形,並顯示一個運行時錯誤:RuntimeError:無法將單個藝術家放在多個圖中。我不知道我做錯了:在python底圖上繪製點會產生運行時錯誤
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
數據集'flights.db'可以在這裏找到:https://www.dropbox.com/s/a2wax843eniq12g/flights.db?dl=0 – nigus21