# Shared colorbar for all heatmap subplots

**URL:** <https://discourse.holoviz.org/t/shared-colorbar-for-all-heatmap-subplots/448>\
**Category:** HoloViews\
**Created:** [April 8, 2020, 12:09pm UTC](https://discourse.holoviz.org/t/shared-colorbar-for-all-heatmap-subplots/448 "2020-04-08T12:09:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rhyst223](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/r/df788c/32.png) [@Rhyst223](https://discourse.holoviz.org/u/Rhyst223)\
**Post date:** [April 8, 2020, 12:09pm UTC](https://discourse.holoviz.org/t/shared-colorbar-for-all-heatmap-subplots/448/1 "2020-04-08T12:09:13Z")

</div>

Suppose I have 3 heatmap plots of the form

(a.hvplot.heatmap(x=‘x’,y=‘y’,C=‘z’) + b.hvplot.heatmap(x=‘x’,y=‘y’,C=‘z’) + c.hvplot.heatmap(x=‘x’,y=‘y’,C=‘z’)).col(3)

Is there any way in which I can have one colorbar for all 3 subplots? Currently, setting colorbar=True for each plot has each subplot with its own colorbar. If I have colorbar=False for all but one, only one colorbar is shown, but does this mean that the values in all subplots will correspond to the same colorbar?

---

<div class="post-metadata">

**Author:** ![iuryt](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/iuryt/32/5701_2.png) [@iuryt](https://discourse.holoviz.org/u/iuryt)\
**Post date:** [July 1, 2024, 7:49pm UTC](https://discourse.holoviz.org/t/shared-colorbar-for-all-heatmap-subplots/448/2 "2024-07-01T19:49:26Z")

</div>

@ahuang11 , do you know if this is currently available? I have the same question and couldn’t find an example in the documentation.

I created a code snippet that can be used as an example:

```python
import xarray as xr
import numpy as np
import hvplot.xarray
import holoviews as hv

n = 100
x = xr.DataArray(np.linspace(0,2*np.pi,n), dims=["x"]).rename("x")
y = xr.DataArray(np.linspace(0,2*np.pi,n), dims=["y"]).rename("y")
z = [(np.sin(x-t)*np.cos(y-t)) for t in np.linspace(0,np.pi/2,4)]

plots = [zi.hvplot.quadmesh(x="x", y="y", width=300, height=300) for zi in z]
layout = hv.Layout(plots).cols(2)
layout

```

 ![image](https://discourse.holoviz.org/uploads/default/original/2X/5/5f84a0ff4d65a01faed14e2e783b5189503e5a62.jpeg)

---

<div class="post-metadata">

**Author:** ![ahuang11](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/ahuang11/32/4947_2.png) [@ahuang11](https://discourse.holoviz.org/u/ahuang11)\
**Post date:** [July 1, 2024, 9:05pm UTC](https://discourse.holoviz.org/t/shared-colorbar-for-all-heatmap-subplots/448/3 "2024-07-01T21:05:03Z")

</div>

Ah, I found the [issue on GitHub](https://github.com/holoviz/holoviews/issues/4237); I’ve wanted this since 2020 (or probably earlier), and with Panel, I think it’s doable.

```python
import xarray as xr
import hvplot.xarray
import panel as pn
ds = xr.tutorial.open_dataset('air_temperature').isel(time=[0, 4, 7, 8])
l = ds.hvplot('lon', 'lat', colorbar=False).layout()
plots = l.cols(2)

shared_colorbar = l.values()[0].clone().opts(
    colorbar=True,
    frame_width=0,
    frame_height=500,
    show_frame=False,
    shared_axes=False,
    xaxis=None,
    yaxis=None,
    toolbar=None,
    colorbar_opts={"width": 50, "height": 400, "title": "Temperature (°C)"},
)
# colorbar_opts: background_fill_alpha, background_fill_color, bar_line_alpha, bar_line_cap, bar_line_color, bar_line_dash, bar_line_dash_offset, bar_line_join, bar_line_width, border_line_alpha, border_line_cap, border_line_color, border_line_dash, border_line_dash_offset, border_line_join, border_line_width, color_mapper, context_menu, coordinates, display_high, display_low, elements, formatter, group, height, js_event_callbacks, js_property_callbacks, label_standoff, level, location, major_label_overrides, major_label_policy, major_label_text_align, major_label_text_alpha, major_label_text_baseline, major_label_text_color, major_label_text_font, major_label_text_font_size, major_label_text_font_style, major_label_text_line_height, major_label_text_outline_color, major_tick_in, major_tick_line_alpha, major_tick_line_cap, major_tick_line_color, major_tick_line_dash, major_tick_line_dash_offset, major_tick_line_join, major_tick_line_width, major_tick_out, margin, minor_tick_in, minor_tick_line_alpha, minor_tick_line_cap, minor_tick_line_color, minor_tick_line_dash, minor_tick_line_dash_offset, minor_tick_line_join, minor_tick_line_width, minor_tick_out, name, orientation, padding, propagate_hover, renderers, scale_alpha, subscribed_events, syncable, tags, ticker, title, title_standoff, title_text_align, title_text_alpha, title_text_baseline, title_text_color, title_text_font, title_text_font_size, title_text_font_style, title_text_line_height, title_text_outline_color, visible, width, x_range_name or y_range_name

pn.Row(plots, shared_colorbar, align="center")

```

 ![image](https://discourse.holoviz.org/uploads/default/original/2X/c/c1091bcaa38189c6b480c7d8e1c35091b7b530e4.png)

---

<div class="post-metadata">

**Author:** ![iuryt](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/iuryt/32/5701_2.png) [@iuryt](https://discourse.holoviz.org/u/iuryt)\
**Post date:** [July 1, 2024, 9:57pm UTC](https://discourse.holoviz.org/t/shared-colorbar-for-all-heatmap-subplots/448/4 "2024-07-01T21:57:13Z")

</div>

Thanks, I will continue the discussion in the GitHub issue.
