Colormaps for dummys

743 views
Skip to first unread message

Bobby Henley

unread,
Nov 15, 2016, 1:16:34 PM11/15/16
to pyqtgraph
Hi, I'm very new to the idea of colormaps, I've always just used matplotlib and had it done for me.
Does pyqtgraph have any built in colormaps in the way that matplotlib does?
I'm now writing something where I would like to display my stack of images in ImageView with something like a cubehelix colormap. Can someone point me in the direction of a straightforward idiot proof tutorial on how this is done? I've searched for similiar topics in the group but its all going over my head. 

Vincent Le Saux

unread,
Nov 17, 2016, 2:55:30 PM11/17/16
to pyqtgraph
Hi,

I've already added some colormap into pyqtgraph for my personal app. It is pretty easy to do. I'll suggest you one solution tomorrow (with an example).  If you already want to have a look, all is in the GradientEditorItem.py file and in the Gradient ordered dict. You just have to add some entries.

Vincent

Bobby Henley

unread,
Nov 30, 2016, 2:46:57 PM11/30/16
to pyqtgraph
Hi Vincent, any update on this?

Vincent Le Saux

unread,
Nov 30, 2016, 4:56:49 PM11/30/16
to pyqtgraph
Unfortunately not. I'll try to propose a pull request that add some interesting colormaps (such as jet, inferno, viridis and cubehelix) tomorrow or friday... I'll post the code here.

Keep in touch!

Vincent

Sebastian Höfer

unread,
Dec 7, 2016, 5:38:17 AM12/7/16
to pyqtgraph
Hi,

I had the same problem a while ago when Matplotlib got the new "Viridis" color scheme and I wanted to use this (and some more) in my application. Until now the format of the colormaps for the ImageView widget are pretty simple and, as Vincent wrote before, you can just add your own at the top of the GradientEditorItem.py.
The Matplotlib cmaps work a bit different and there're actually several modes how to define your colors. For example is "viridis" just a list of 256 RGB-tuples, while "cubehelix" is generated by a parameterizable function. So you have to convert each of these into Pyqtgraph's format. I started doing that, but after the first two I decided to just convert them all.

So ... in the attached file is the ImageView example from PyQtgraph, extended with a converter function that converts any Matplotlib colormap to PyQtgraph's format and a modified ImageView that "monkey patches" the new colormap into the context menu of the GradientEditorWidget. I hope you find it useful. :)

I  planed to make a pull request with the converter added to colormap.py and an extended init-function for the GradientEditor that accepts additional colormaps. If somebody wants to include it before I find the time .... feel free. :)

Sebastian
mpl_cmaps_in_ImageView.py
Reply all
Reply to author
Forward
0 new messages