谁能指导我如何将图例添加到 mplleaflet html 图中。其次如何选择初始缩放?
在 geopandas 中打开 shapefile 并在交互式网络 map 上绘制属性
示例代码:
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)
示例图片: 例如,我想立即放大到东南亚
最佳答案
我认为,目前您想要的功能尚未实现。
关于图例的第一个问题,请看这里: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)
这远非完美,只有当你想要进一步观察时才有效(我不知道英语是否是这样说的)但总比没有好。
ax.set_xlim
和/或 ax.set_ylim
不起作用,因此您的缩放比例不能比您想要在 map 中绘制的区域更近。
希望对你有帮助。
关于python - 单张 : Add the plot legend and select initial zoom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37091708/