我喜欢以下语法制作地图的便利:
import geopandas
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world.plot(column='continent',legend=True,legend_kwds = {'loc':'lower left'})
但是,我正在寻找一种方法来改变由此产生的标记的形状。默认情况下(使用非连续变量),geopandas(或 matplotlib)生成实心圆圈。
我真的很想将这些标记填充在带有黑色细边框的矩形中。
我尝试在
marker
中使用plot
参数但没有成功。我也在legend_kwds
中尝试过各种论点。
使用
geopandas
很难找到编辑图例属性或获取图例对象的方法。这是一条路要走。
一旦掌握了图例,就可以根据需要更改其属性。在下面的代码中,标记的形状、边缘颜色、边缘宽度都按需要设置。
import geopandas
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
ax = world.plot(figsize=(12,9) ,column='continent',legend=True,legend_kwds = {'loc':'lower left'})
leg1 = ax.get_legend()
for ea in leg1.legendHandles:
ea.set_marker('s')
ea.set_markeredgecolor('k')
ea.set_markeredgewidth(0.5)