2021-01-05 06:01:30 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2021-06-26 15:41:57 +00:00
|
|
|
This example displays all color maps currently available, either as local data
|
|
|
|
or imported from Matplotlib of ColorCET.
|
2021-01-05 06:01:30 +00:00
|
|
|
"""
|
|
|
|
## Add path to library (just for examples; you do not need this)
|
|
|
|
import initExample
|
|
|
|
|
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
|
|
|
import pyqtgraph as pg
|
|
|
|
|
|
|
|
app = pg.mkQApp()
|
|
|
|
|
|
|
|
win = QtGui.QMainWindow()
|
|
|
|
win.resize(1000,800)
|
|
|
|
|
|
|
|
lw = pg.GraphicsLayoutWidget()
|
|
|
|
lw.setFixedWidth(1000)
|
2021-06-06 01:17:43 +00:00
|
|
|
lw.setSizePolicy(QtGui.QSizePolicy.Policy.Expanding, QtGui.QSizePolicy.Policy.Expanding)
|
2021-01-05 06:01:30 +00:00
|
|
|
|
|
|
|
scr = QtGui.QScrollArea()
|
2021-06-06 01:17:43 +00:00
|
|
|
scr.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
|
2021-01-05 06:01:30 +00:00
|
|
|
scr.setWidget(lw)
|
|
|
|
win.setCentralWidget(scr)
|
|
|
|
win.setWindowTitle('pyqtgraph example: Color maps')
|
2021-06-09 03:41:46 +00:00
|
|
|
win.show()
|
2021-01-05 06:01:30 +00:00
|
|
|
|
2021-06-09 03:41:46 +00:00
|
|
|
bar_width = 32
|
|
|
|
bar_data = pg.colormap.modulatedBarData(width=bar_width)
|
2021-01-05 06:01:30 +00:00
|
|
|
|
|
|
|
num_bars = 0
|
|
|
|
|
2021-06-09 03:41:46 +00:00
|
|
|
def add_heading(lw, name):
|
|
|
|
global num_bars
|
|
|
|
lw.addLabel('=== '+name+' ===')
|
2021-01-05 06:01:30 +00:00
|
|
|
num_bars += 1
|
2021-06-09 03:41:46 +00:00
|
|
|
lw.nextRow()
|
|
|
|
|
|
|
|
def add_bar(lw, name, cm):
|
|
|
|
global num_bars
|
|
|
|
lw.addLabel(name)
|
|
|
|
imi = pg.ImageItem( bar_data )
|
|
|
|
imi.setLookupTable( cm.getLookupTable(alpha=True) )
|
2021-01-05 06:01:30 +00:00
|
|
|
vb = lw.addViewBox(lockAspect=True, enableMouse=False)
|
2021-06-09 03:41:46 +00:00
|
|
|
vb.addItem( imi )
|
|
|
|
num_bars += 1
|
2021-01-05 06:01:30 +00:00
|
|
|
lw.nextRow()
|
|
|
|
|
2021-06-09 03:41:46 +00:00
|
|
|
add_heading(lw, 'local color maps')
|
|
|
|
list_of_maps = pg.colormap.listMaps()
|
2021-06-26 15:41:57 +00:00
|
|
|
list_of_maps = sorted( list_of_maps, key=lambda x: x.swapcase() )
|
2021-06-09 03:41:46 +00:00
|
|
|
for map_name in list_of_maps:
|
|
|
|
cm = pg.colormap.get(map_name)
|
|
|
|
add_bar(lw, map_name, cm)
|
|
|
|
|
|
|
|
add_heading(lw, 'Matplotlib import')
|
2021-01-05 06:01:30 +00:00
|
|
|
list_of_maps = pg.colormap.listMaps('matplotlib')
|
2021-06-26 15:41:57 +00:00
|
|
|
list_of_maps = sorted( list_of_maps, key=lambda x: x.lower() )
|
2021-01-05 06:01:30 +00:00
|
|
|
for map_name in list_of_maps:
|
2021-06-09 03:41:46 +00:00
|
|
|
cm = pg.colormap.get(map_name, source='matplotlib', skipCache=True)
|
|
|
|
if cm is not None:
|
|
|
|
add_bar(lw, map_name, cm)
|
2021-01-05 06:01:30 +00:00
|
|
|
|
2021-06-09 03:41:46 +00:00
|
|
|
add_heading(lw, 'ColorCET import')
|
2021-06-26 15:41:57 +00:00
|
|
|
list_of_maps = pg.colormap.listMaps('colorcet')
|
|
|
|
list_of_maps = sorted( list_of_maps, key=lambda x: x.lower() )
|
2021-01-05 06:01:30 +00:00
|
|
|
for map_name in list_of_maps:
|
2021-06-09 03:41:46 +00:00
|
|
|
cm = pg.colormap.get(map_name, source='colorcet', skipCache=True)
|
|
|
|
if cm is not None:
|
|
|
|
add_bar(lw, map_name, cm)
|
|
|
|
|
|
|
|
lw.setFixedHeight(num_bars * (bar_width+5) )
|
2021-01-05 06:01:30 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-05-13 21:28:22 +00:00
|
|
|
pg.exec()
|