删除 pvplot 中网格热图的左侧 ColorBar

Remove left ColorBar of grid heatmap plot in pvplot

我尝试通过 pvplot 制作网格热图。我指的是这个link。 https://hvplot.pyviz.org/user_guide/Subplots.html

import hvplot.pandas
from bokeh.sampledata.unemployment1948 import data

data.Year = data.Year.astype(str)
data = data.set_index('Year')
data.drop('Annual', axis=1, inplace=True)
data.columns.name = 'Month'

df = pd.DataFrame(data.stack(), columns=['rate']).reset_index()
df = df.tail(40)
df['group'] = [1,2]*20
df.hvplot.heatmap(x='Year', y='Month', C='rate', col='group', colorbar=True)

热图

我预计左侧颜色条不会显示。共享轴可以像 link 页面那样对齐。谁能告诉我 pvplot 是否支持这个?谢谢

您创建的全息视图对象是所谓的gridspace。它包含数据中每个组的单独图。
您可以通过组名访问每个组的绘图。您示例中的组名称是 1 和 2。想法是仅在组 1 的图上使用 colorbar=False

您可以像这样从第一组中删除颜色条:

# create a variable that holds your gridspace plots
grid_space_groups = df.hvplot.heatmap(x='Year', y='Month', C='rate', col='group')

# checking the names of your groups in your gridspace
print(grid_space_groups.keys())

# removing the colorbar from the plot with the group that has name '1'
grid_space_groups[1] = grid_space_groups[1].opts(colorbar=False)

# plot your grid space 
grid_space_groups


请注意:
当您的颜色条没有相同的值范围时,您首先必须确保它们都具有相同的范围。您可以对列 rate:
这样做 grid_space_groups.redim.range(rate=(0, 10))

或者,您可以为每个组分别创建每个图。
第 1 组的绘图,您使用 colorbar=False 在没有颜色条的情况下创建,以及您使用颜色条创建的第 2 组的绘图:

plot_1 = df[df.group == 1].hvplot.heatmap(x='Year', y='Month', C='rate', colorbar=False)
plot_2 = df[df.group == 2].hvplot.heatmap(x='Year', y='Month', C='rate')
plot_1 + plot_2