hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

Adding scientific colorbar like roma

Open mohseniaref opened this issue 2 years ago • 3 comments

Dear all

I was wondering if it is possible to add scientific colorbar like crameri in hvplot. it can be installed easily in python using

pip install cmcrameri

I have tried to use it in hvplot but it seems hvplot choice is limited to predefined

https://www.fabiocrameri.ch/colourmaps/

best regards, Mohammad

mohseniaref avatar Jan 04 '23 07:01 mohseniaref

I'd expect that hvPlot would accept any Matplotlib colormap or Bokeh palette, but please add a reproducible example demonstrating otherwise if that's not what you're finding.

In any case I know that the underlying HoloViews library can accept any Matplotlib colormap or Bokeh palette, so in the worst case you can add .opts(cmap=XX), where XX is any such colormap or palette, once you've gotten a HoloViews object from your hvPlot call.

jbednar avatar Jan 04 '23 21:01 jbednar

Hi

Thanks for your response. Maybe I didn't explain clear. I think some of matplotlib or hvplot colormap might not be ideal for case of people who are color blind or might not good reprentative.

(https://www.fabiocrameri.ch/colourmaps-userguide/)

I can use for instance colorplot outside matplotlib like cmcrameri in following example. I think it would be wonderful if it could be possible for hvplot

from cmcrameri import cm
import numpy as np
from scipy import misc
import matplotlib.pyplot as plt
y = misc.face(gray=True)
y.hvplot(cmap=cm.berlin)

I can not do same for hvplot for instance

import xarray as xr

xr_ds = xr.tutorial.open_dataset('air_temperature').load().sel(time='2013-06-01 12:00')
xr_ds.hvplot(cmap=cm.roma)  

mohseniaref avatar Jan 05 '23 10:01 mohseniaref

No problem; I just didn't explain that by "Matplotlib colormap" I didn't mean "included with Matplotlib", I meant "a colormap whose type is the same as those provided with Matplotlib". The crameri colormaps are indeed of that type and thus should work, but they fail with hvplot:

image

In the short term, that's no problem; just set the colormap using HoloViews options instead:

image

But we should fix hvplot to work properly with these colormaps; it's certainly intended that they work when provided directly to the hvplot call.

jbednar avatar Jan 05 '23 17:01 jbednar