python - 单张 : Add the plot legend and select initial zoom

标签 python matplotlib leaflet geopandas

谁能指导我如何将图例添加到 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)

示例图片: 例如,我想立即放大到东南亚

World map

最佳答案

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

关于图例的第一个问题,请看这里: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/

相关文章:

python - 自动将 for 循环列表理解中列表中的所有元素发送到函数中

Python 3.2.3、easy_install、Mac OS X

Python/Webdriver 检查选择选项被禁用

python matplotlib : mark dots over Line2D

api - 将传单与谷歌地图一起使用?

python - 如何隐藏 "py4j.java_gateway:Received command c on object id p0"?

python - 剧情表现怪异

python - 如何防止 matplotlib 在水平轴上显示小数年份

javascript - 由 OSM 数据转换而来的 Leaflet + GeoJson - 关系

javascript - 在 jQuery Mobile 面板中显示 geoJSON 属性