已安装的软件包
geoviews 1.9.1.,matplotlib 3.4.2。
我正在尝试做什么
For the Bokeh
后端通过添加分类图例GeoViews
是通过代理艺术家完成的,如中所述卡特里娜飓风路径示例 https://geoviews.org/gallery/bokeh/katrina_track.html,我设法让它发挥作用,但是这对Matplotlib
后端?相应的卡特里娜飓风跟踪案例的 mpl 示例 https://geoviews.org/gallery/matplotlib/katrina_track.html#matplotlib-gallery-katrina-track,特别是不包括图例。另一个mpl
带图例的示例都使用颜色条。
The HoloViews
图例示例 http://holoviews.org/gallery/demos/matplotlib/legend_example.html表明这是自动完成的,所以我认为这同样适用于GeoViews
但是当尝试使用 GeoDataFrames 作为输入来重现示例时gv.Polygons
,没有出现图例。
可重现的例子
import pandas as pd
import geopandas as gpd
import geoviews as gv
from geoviews import opts
gv.extension('matplotlib')
d1 = {'use': {0: 'Residential', 1: 'Residential'},
'geometry': {0: 'POLYGON ((13.80961103741604 51.04076975651729, 13.80965521888065 51.04079016168103, 13.80963851766593 51.04080454197601, 13.80959433642561 51.04078412781548, 13.80961103741604 51.04076975651729))',
1: 'POLYGON ((13.80977831740752 51.04313480566009, 13.80987122363639 51.04306085051974, 13.8099989591537 51.04312462457182, 13.80995486494384 51.04315973323087, 13.8099651184249 51.04316486464228, 13.80991634926543 51.04320371166482, 13.80977831740752 51.04313480566009))'}}
gdf1 = gpd.GeoDataFrame(pd.DataFrame(d1), geometry=gpd.GeoSeries.from_wkt(pd.DataFrame(d1)['geometry']), crs="EPSG:4326")
d2 = {'geometry': {1: 'POLYGON ((13.80894179055831 51.04544128170094, 13.80952887156242 51.0450399782091, 13.80954152432486 51.04504668985658, 13.80896834397535 51.04545611172818, 13.80894179055831 51.04544128170094))'}}
gdf2 = gpd.GeoDataFrame(pd.DataFrame(d2), geometry=gpd.GeoSeries.from_wkt(pd.DataFrame(d2)['geometry']), crs="EPSG:4326")
feature1 = gv.Polygons(gdf1, group="group1", label='label1')
feature2 = gv.Polygons(gdf2, group="group2", label='label2')
layout = feature1.opts(color='red') * feature2.opts(color='lightgrey')
layout.opts(
opts.Polygons('group1', cmap=['red'], edgecolor='black', linewidth=0.5, xaxis=None, yaxis=None),
opts.Polygons('group2', cmap=['lightblue'], edgecolor='blue', linewidth=0.5),
opts.Overlay(fig_size=500)
)
gv.output(layout)
任何指示将不胜感激(如果可能的话,在更早的相关SO问题 https://stackoverflow.com/questions/68318769/geoviews-applying-matplotlib-styling-parameters-to-polygons-elements我几周前的作品)。