这可能是一种不寻常的情况,因此Holoviews确实不支持它。
我彼此之间有两个图像叠加层(xarray),每个像素的NaN值用于混合两个不同的cmap-红色和蓝色。我想将两个颜色条作为图例彼此相邻。当前,绘制的最后一个颜色条会覆盖第一个颜色条:
image_layer_1 = img_grid.opts(
color_levels=cat_count,
cmap=cmap_with_nodata,
colorbar=True,
clipping_colors={'NaN': 'transparent'},
colorbar_opts={
'major_label_text_align':'left',
'major_label_overrides': label_dict,
'ticker': FixedTicker(
ticks=list(range(0, len(label_dict)))),
},
tools=[hover],
**optional_kwargs_unpack
)
...
gv_layers = (gf.ocean.opts(alpha=alpha, fill_color=fill_color) * \
image_layer_1 * \
image_layer_2 * \
gf.coastline.opts(line_color=edgecolor) * \
gf.borders.opts(line_color=edgecolor)
).opts(
bgcolor=bg_color,
projection=crs.Mollweide(),
responsive=responsive,
data_aspect=1,
hooks=[set_active_tool],
title=title)
philippjfr解释了here如何通过以下方式手动绘制图例:
legend = (image_layer_1 + image_layer_2).opts(
hv.opts.HeatMap(frame_width=0, colorbar=True, xaxis=None, yaxis=None, show_frame=False),
clone=False
)
gv_layers = ((gf.ocean.opts(alpha=alpha, fill_color=fill_color) * \
image_layer_1 * \
image_layer_2 * \
gf.coastline.opts(line_color=edgecolor) * \
gf.borders.opts(line_color=edgecolor)
).opts(
bgcolor=bg_color,
projection=crs.Mollweide(),
responsive=responsive,
data_aspect=1,
hooks=[set_active_tool],
title=title) + legend)
当我正确地获得两个颜色条时,将复制情节本身:
有什么办法可以在主图旁边(理想情况下带有标题)仅显示两个颜色条(蓝色和红色)?