[Matplotlib-users] 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 : 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
Re: [Matplotlib-users] register colormap collection
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 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 : > > > > 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 > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] register colormap collection
On Thu, Oct 1, 2015 at 9:40 AM, Thomas Caswell wrote: > 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 > FWIW -- this second option is exactly what I do for custom colormaps and Axes scales. https://github.com/Geosyntec/wqio/blob/master/wqio/utils/__init__.py#L10 -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users