holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.14k stars 108 forks source link

Adding scientific colorbar like roma #1012

Open mohseniaref opened 1 year ago

mohseniaref commented 1 year ago

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

jbednar commented 1 year ago

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.

mohseniaref commented 1 year ago

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)  
jbednar commented 1 year ago

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.