mplleaflet:添加图例并选择初始缩放

Phi*_*arz 6 python matplotlib leaflet geopandas

谁能指导我如何向 mplleaflet html 图中添加图例。其次如何选择初始变焦?

在 geopandas 中打开 shapefile 并在交互式网络地图上绘制属性

示例代码:

import geopandas as gp
shapefile = 'shapefile/ne_50m_admin_0_countries.shp'
df_shapefile_countries = gpd.GeoDataFrame.from_file(shapefile)

import mplleaflet
ax = df_shapefile_countries .plot(column='pop_est')
mplleaflet.show(fig=ax.figure)
Run Code Online (Sandbox Code Playgroud)

示例图像:我想立即缩放到例如东南亚

世界地图

kik*_*oso 3

我认为,目前您想要的功能尚未实现。

关于图例的第一个问题,请查看这里:https ://github.com/jwass/mplleaflet/issues/35

对于第二个问题,发挥创意,您​​可以进行缩放,使用您想要的坐标创建透明绘图。例如,看看下面的代码:

import matplotlib.pyplot as plt
import mplleaflet

fig, ax = plt.subplots()

# Your plot
ax.plot([10, 20, 30], [10, 20, 30])

# A second plot with some coordinates you want to use as the limits
# For instance, I want a plot with  x between (-100, 100)
ax.plot([-100, 100], [10, 30], alpha = 0)

mplleaflet.show(fig = ax.figure)
Run Code Online (Sandbox Code Playgroud)

这远非完美,只有在您想要进一步查看时才有效(我不知道英语是否是这样说的),但总比没有好。 ax.set_xlim和/或ax.set_ylim不起作用,因此您无法将变焦放大到比您想要在地图中绘制的范围更近。

我希望它有帮助。

  • 两年半过去了,这件事有什么更新吗?实现这些功能将非常有用。 (3认同)