Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for new function : Matplotlib colormap format #1110

Open
egayer opened this issue Jun 1, 2024 · 1 comment
Open

Request for new function : Matplotlib colormap format #1110

egayer opened this issue Jun 1, 2024 · 1 comment
Labels
Milestone

Comments

@egayer
Copy link

egayer commented Jun 1, 2024

Hi guys,

While the color scale functions in lets-plot are awesome, I would like to propose adding a function that can read any colormap given in the Matplotlib format. This would be different from ..._color_brewer() and ..._color_viridis() as it would take the name of the colormap imported from another package as an argument.

Several packages exist for scientific colormaps (cmcrameri, CMOcean, etc., see this article) and most of them are designed so colormaps can be directly used with Matplotlib.

In order to use such colormaps with lets-plot, I wrote a small function (ggcmap2hex()) that translates colormaps (in Matplotlib format) into a list of hex codes. The list can then be used in the scale_xxxx_gradientn() function in lets-plot (xxxx being either fill or color).

Currently, this function relies on Matplotlib, which makes it dependent on Matplotlib and on its versions. Which is not what you want but I couldn't code it natively for lets-plot :$

It would be super cool if you guys could implement such a function to be used in scale_xxxx_gradientn(). Or to create a new function called something like scale_xxxx_colormap() or scale_xxxx_cmap() that would do scale_xxxx_gradientn(colors=ggcmap2hex(cm.jet)) such as :

from matplotlib import cm
...
...
 + scale_color_cmap(cm.turbo)

or

import cmcrameri.cm as cmc
...
...
 + scale_fill_cmap(cmc.batlow)

I attached a notebook that contains ggcmap2hex() and a demo.
ggcmap2hex.zip

@alshan
Copy link
Collaborator

alshan commented Jun 4, 2024

Thanx! this is interesting, certainly worth considering.

@alshan alshan added the * label Jun 4, 2024
@alshan alshan added this to the New milestone Jun 4, 2024
@alshan alshan modified the milestones: New, 2024Q3 Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants