register colormap collection

Hi all,

I have a question about how to permanently register customs colormap into matplolib. I went across the cookbook and the definition of cm.register, I also checked on stack overflow and found this post

http://stackoverflow.com/questions/8738239/permanently-registering-colormaps-in-matplotlib

but I still quite don’t understand how the registration works, and how to make the registration working across different scripts.

I have a set of colormap that I manage to transform from their original format (.cpt or .clr) to matplotlib object :

<matplotlib.colors.LinearSegmentedColormap object at 0x1033406d0>

My first though was that I could register these colormap objects once as list for exemple, and then call them anytime in any script, the same way we do call any matploltlib colormap preset with matplotlib.cm.jet etc…

It looks like this is not possible since register a colormap, and call it using get_map(mycmap) does not work across different script.

I clearly don’t get the logic behind the registration of the colormap, and I am looking for a way to stock all my custom colormap somewhere in a file or module, that I could import in every script and then call the colormap the way we call the matplotlib colormap collection, maybe not using matplolib.cm. but with a custom function similar to.

Thanks for helping me understand le logic of “saving”/registring colormaps and pointing me to direction to create my own colormap collection and a simple way to use them

Eric

Have a look at how cmocean (https://github.com/matplotlib/cmocean) works under the hood.

I think the options are:

  • use a module to supply your color maps (from my_cmap_collection import my_cmap) and then pass those objects through to the functions

  • have your module call the register code on import (or on calling a helper function which call the registration code) so that you can simply pass the string name through and get_cmap will do the right thing.

Tom

···

On Thu, Oct 1, 2015 at 6:20 AM Eric Gayer <egayer@…287…> wrote:

Hi all,

I have a question about how to permanently register customs colormap into matplolib. I went across the cookbook and the definition of cm.register, I also checked on stack overflow and found this post

http://stackoverflow.com/questions/8738239/permanently-registering-colormaps-in-matplotlib

but I still quite don’t understand how the registration works, and how to make the registration working across different scripts.

I have a set of colormap that I manage to transform from their original format (.cpt or .clr) to matplotlib object :

<matplotlib.colors.LinearSegmentedColormap object at 0x1033406d0>

My first though was that I could register these colormap objects once as list for exemple, and then call them anytime in any script, the same way we do call any matploltlib colormap preset with matplotlib.cm.jet etc…

It looks like this is not possible since register a colormap, and call it using get_map(mycmap) does not work across different script.

I clearly don’t get the logic behind the registration of the colormap, and I am looking for a way to stock all my custom colormap somewhere in a file or module, that I could import in every script and then call the colormap the way we call the matplotlib colormap collection, maybe not using matplolib.cm. but with a custom function similar to.

Thanks for helping me understand le logic of “saving”/registring colormaps and pointing me to direction to create my own colormap collection and a simple way to use them

Eric



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

FWIW -- this second option is exactly what I do for custom colormaps and
Axes scales.

···

On Thu, Oct 1, 2015 at 9:40 AM, Thomas Caswell <tcaswell@...287...> wrote:

Have a look at how cmocean (GitHub - matplotlib/cmocean: Colormap setup for standardizing commonly-plotting oceanographic variables.) works
under the hood.

I think the options are:
   - use a module to supply your color maps (from my_cmap_collection
import my_cmap) and then pass those objects through to the functions
   - have your module call the register code on import (or on calling a
helper function which call the registration code) so that you can simply
pass the string name through and `get_cmap` will do the right thing.

Tom