1

已安装的软件包

geoviews 1.9.1.,matplotlib 3.4.2。

我正在尝试做的事情

对于Bokeh后端添加分类图例GeoViews是通过代理艺术家完成的,如卡特里娜飓风示例中所述,我设法让它工作,但这对Matplotlib后端有什么作用?Katrina 轨道案例的相应mpl 示例,特别是不包括图例。其他mpl带有图例的示例都使用颜色条。

HoloViews 图例示例表明这是自动完成的,所以我认为同样适用,但是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 问题上)。

4

0 回答 0