在Basemap上将饼图放置在地图上

2 投票
1 回答
1533 浏览
提问于 2025-04-18 10:21

我想在地图上用Basemap和Matplotlib画饼图。

你知道怎么做吗?

1 个回答

3

你可以通过 inset_axes 在基础地图上添加一个坐标轴。我对第一个例子 这里 做了一些修改,加入了一个饼图。

from mpl_toolkits.basemap import Basemap
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
import matplotlib.pyplot as plt

# setup Lambert Conformal basemap.
fig = plt.figure()
ax = fig.add_subplot(111)
m = Basemap(width=12000000,height=9000000,projection='lcc',
            resolution='c',lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.,ax=ax)
# draw coastlines.
m.drawcoastlines()
# draw a boundary around the map, fill the background.
# this background will end up being the ocean color, since
# the continents will be drawn on top.
m.drawmapboundary(fill_color='aqua')
# fill continents, set lake color same as ocean color.
m.fillcontinents(color='coral',lake_color='aqua')

axin = inset_axes(m.ax,width="30%",height="30%", loc=3)
axin.pie([100,200,3000])
plt.show()

饼图在地图上

撰写回答