要實現互動式地圖可視化,可以使用Matplotlib的Basemap工具包結合mplleaflet庫。具體步驟如下:
pip install basemap
pip install mplleaflet
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import mplleaflet
m = Basemap(projection='mill',llcrnrlat=-90,urcrnrlat=90,llcrnrlon=-180,urcrnrlon=180,resolution='c')
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary()
lons = [longitude1, longitude2, ...]
lats = [latitude1, latitude2, ...]
x, y = m(lons, lats)
m.scatter(x, y, color='red', marker='o', zorder=5)
plt.title('Interactive Map Visualization')
mplleaflet.display()
通過這些步驟,即可實現基于Matplotlib的互動式地圖可視化。