# Using Matplotlib Normalized Colobars

**URL:** <https://discourse.holoviz.org/t/using-matplotlib-normalized-colobars/8604>\
**Category:** hvPlot\
**Created:** [February 25, 2025, 2:33pm UTC](https://discourse.holoviz.org/t/using-matplotlib-normalized-colobars/8604 "2025-02-25T14:33:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abfunk](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/a/e79b87/32.png) [@abfunk](https://discourse.holoviz.org/u/abfunk)\
**Post date:** [February 25, 2025, 2:33pm UTC](https://discourse.holoviz.org/t/using-matplotlib-normalized-colobars/8604/1 "2025-02-25T14:33:26Z")

</div>

I’d like to use Matplotlib’s colorbar normalization when plotting with hvplot.image(). For instance, I’d like to use the Matplotlib function PowerNorm ([matplotlib.colors.PowerNorm — Matplotlib 3.10.0 documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.colors.PowerNorm.html)).

Does anyone know if there is a way to do this and if so, what’s the best way? Can the “norm=” argument be used to pass a colorbar? I’ve so far been unsuccessful at the latter and I’m hoping maybe someone here knows how best to do this. Thanks.

hvplot=0.11.2  
holoviews=1.20.0  
matplotlib=3.10.0

Aaron

---

<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:** [February 25, 2025, 5:44pm UTC](https://discourse.holoviz.org/t/using-matplotlib-normalized-colobars/8604/2 "2025-02-25T17:44:38Z")

</div>

Theoretically `cnorm`

Alternatively, you could use hooks to manually add the colorbar:  
[https://holoviews.org/user\_guide/Customizing\_Plots.html#plot-hooks](https://holoviews.org/user_guide/Customizing_Plots.html#plot-hooks)

Or also backend\_opts  
[https://holoviews.org/user\_guide/Plotting\_with\_Matplotlib.html#setting-backend-opts](https://holoviews.org/user_guide/Plotting_with_Matplotlib.html#setting-backend-opts)

```auto
import hvplot.xarray
import xarray as xr
import holoviews as hv

hv.extension("matplotlib")

ds = xr.tutorial.open_dataset("air_temperature")
hv.help(hv.Image(ds.isel(time=0), ["lon", "lat"]).opts(colorbar=True))

```

---

<div class="post-metadata">

**Author:** ![abfunk](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/a/e79b87/32.png) [@abfunk](https://discourse.holoviz.org/u/abfunk)\
**Post date:** [February 25, 2025, 7:28pm UTC](https://discourse.holoviz.org/t/using-matplotlib-normalized-colobars/8604/3 "2025-02-25T19:28:26Z")

</div>

Thank you for the reply. I’ll try the plot hooks and see if I can get it to work.

---

<div class="post-metadata">

**Author:** ![abfunk](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/a/e79b87/32.png) [@abfunk](https://discourse.holoviz.org/u/abfunk)\
**Post date:** [February 27, 2025, 1:22pm UTC](https://discourse.holoviz.org/t/using-matplotlib-normalized-colobars/8604/4 "2025-02-27T13:22:23Z")

</div>

I wasn’t able to figure out how to pass in a normalization when creating the plot in hvplot, but I was able to hvplot.render(plot) to get the Matplotlib figure and then snoop around the fig’s axes.collections and use the update\_norm() function to achieve what I needed.

 ![TRMM_GPM_rainfall](https://discourse.holoviz.org/uploads/default/original/2X/4/495d1c192b81a8154b35930f5a9725e9fe10dc68.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:** [February 27, 2025, 5:20pm UTC](https://discourse.holoviz.org/t/using-matplotlib-normalized-colobars/8604/5 "2025-02-27T17:20:42Z")

</div>

I think you can extract your downstream code from render

```auto
fig = hvplot.render(plot)
... your code

```

into hook

```auto
def colorbar_hook(plot, element):
    fig = plot.handles["figure"]
   ...your code

ds.hvplot().opts(hooks=[colorbar_hook])

```

---

<div class="post-metadata">

**Author:** ![abfunk](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/a/e79b87/32.png) [@abfunk](https://discourse.holoviz.org/u/abfunk)\
**Post date:** [February 27, 2025, 5:36pm UTC](https://discourse.holoviz.org/t/using-matplotlib-normalized-colobars/8604/6 "2025-02-27T17:36:56Z")

</div>

Thanks. I appreciate the suggestion.
