1

I try to make grid heatmap by pvplot. I refer to this 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)

heatmap

heatmap

I expect left colorbar does not show. And shared axes could be aligned like link page. Can anyone tell if pvplot could support this? Thanks.

kenlukas
  • 3,616
  • 9
  • 25
  • 36
Lundi Lin
  • 35
  • 2
  • 6

1 Answers1

1

The holoviews object you created is a so-called gridspace. It contains a separate plot for every group in your data.
You can access the plot for every group by the name of the group. The names of the groups in your example are 1 and 2. The idea is to use colorbar=False only on the plot for group 1.

You can remove the colorbar from the first group like this:

# 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


Please note:
When your colorbars don't have the same range of values, you first have to make sure that they both have the same range. You can do that like this for column rate:
grid_space_groups.redim.range(rate=(0, 10))

Alternatively, you could create each plot separately for each group.
The plot from group 1, you create without colorbar with colorbar=False, and the plot for group 2 you create with colorbar:

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

left colorbar removed from gridspace holoviews

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96
  • If you use the second approach, does this ensure that all values within subplots will correspond to the same colorbar? – R Thompson Apr 08 '20 at 11:40
  • Great question! No, unfortunately not. If you want to be sure that they both have the same colorbar range, you have to set the range of values of your colorbar dimension yourself. Here the colorbar dimension is a column called 'rate', so you could do it like this: grid_space_groups.redim.range(rate=(0, 10)) – Sander van den Oord May 03 '20 at 18:39