覆盖在catropy底图上的seaborn kdeplot

2024-04-27 10:56:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个kdeplot,我想覆盖在谷歌地图底图之上

sns.kdeplot(dailyreport.long, dailyreport.lat,
             cmap="Reds", shade=True, shade_lowest=False, alpha=.50)

plt.figure(figsize = (12, 12))
img = cimgt.GoogleTiles()
ax = plt.axes(projection = img.crs)
ax.set_extent([-76.849,-77.221,39.017,38.771])
ax.add_image(img, 12)

上述代码导致: Above code result

如何让热图位于谷歌地图的顶部

感谢您的帮助


Tags: trueimg地图pltaxlongcmaplat
2条回答

seaborn抽象掉matplotlib接口的方式,恐怕它不能直接与cartopy一起工作geoplot声称是cartopy的seaborn等价扩展

geoplot的其中一个示例库是kde热图,它看起来像您想要的:

Heatmap of Boston airbnbs

https://residentmario.github.io/geoplot/gallery/plot_boston_airbnb_kde.html#sphx-glr-gallery-plot-boston-airbnb-kde-py

我想出来了。我不得不使用transform=ccrs.PlateCarree()在地图上投影kdeplot

plt.figure(figsize = (12, 12))
img = cimgt.GoogleTiles()
ax = plt.axes(projection = img.crs)
ax.set_extent([-76.849495,-77.22159,39.01713,38.77118])
ax.add_image(img, 12)
sns.kdeplot(dailyreport.long, dailyreport.lat,cmap="Reds", shade=True, shade_lowest=False, alpha=.50,transform = ccrs.PlateCarree())
plt.savefig('map1.png', dpi=100, bbox_inches = 'tight',pad_inches = 0)

Final Output image

相关问题 更多 >