Question about colormaps

76 views
Skip to first unread message

wot

unread,
Jun 17, 2017, 6:27:57 PM6/17/17
to pyqtgraph
First, let me add my praise to that of others. I needed a fast plotting program and this was significantly better than matplotlib. This being said, I have a small problem that probably has a simple solution but I cannot find it.

To get a color map for plotting multiple lines on a graph I currently use the following code:

from matplotlib.pyplot import get_cmap
import numpy as np

numofLines
= 5
cMapType
= 'viridis'
colorMap
= get_cmap(cMapType) # get_cmap is matplotlib object    

colorList
= np.linspace(0, 1, numofLines)
lineColors
= colorMap(colorList)

# convert to RGB*255
lineColors
= lineColors * 255
lineColors
= lineColors.astype(int)

print lineColors

I would like to get away from using maplotlib for this purpose but cannot see how to do this using pyqtgraph. I want to give the user the option to use different color maps 'viridis', 'gist_rainbow' etc. I can store the colormap data in a file with other data if necessary.

aksha...@effectphotonics.nl

unread,
Jun 21, 2017, 4:17:21 AM6/21/17
to pyqtgraph
The following code is an example to use pyqtgraph colormap with an imageview. Maybe this could help you

# ## Set a custom color map
# colors = [
# (0, 0, 0),
# (45, 5, 61),
# (84, 42, 55),
# (150, 87, 60),
# (208, 171, 141),
# (255, 255, 255)
# ]
# cmap = pg.ColorMap(pos=np.linspace(0.0, 1.0, 6), color=colors)
# imv.setColorMap(cmap)
Reply all
Reply to author
Forward
0 new messages