From 675516e0b1f2ebf8412a50a904cac993976d9f0b Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Mon, 22 Mar 2021 22:17:28 -0700 Subject: [PATCH 1/3] collections.abc not just collections --- pyqtgraph/colormap.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/colormap.py b/pyqtgraph/colormap.py index 2ca414a8..3d3c3188 100644 --- a/pyqtgraph/colormap.py +++ b/pyqtgraph/colormap.py @@ -3,7 +3,7 @@ from .Qt import QtGui, QtCore from .python2_3 import basestring from .functions import mkColor, eq from os import path, listdir -import collections +from collections.abc import Callable, Sequence _mapCache = {} @@ -126,7 +126,7 @@ def _get_from_matplotlib(name): col_map = mpl_plt.get_cmap(name) if hasattr(col_map, '_segmentdata'): # handle LinearSegmentedColormap data = col_map._segmentdata - if ('red' in data) and isinstance(data['red'], collections.Sequence): + if ('red' in data) and isinstance(data['red'], Sequence): positions = set() # super-set of handle positions in individual channels for key in ['red','green','blue']: for tup in data[key]: @@ -142,7 +142,7 @@ def _get_from_matplotlib(name): col_data[:,idx] = np.interp(col_data[:,3], positions, comp_vals) cm = ColorMap(pos=col_data[:,-1], color=255*col_data[:,:3]+0.5) # some color maps (gnuplot in particular) are defined by RGB component functions: - elif ('red' in data) and isinstance(data['red'], collections.Callable): + elif ('red' in data) and isinstance(data['red'], Callable): col_data = np.zeros((64, 4)) col_data[:,-1] = np.linspace(0., 1., 64) for idx, key in enumerate(['red','green','blue']): From 5b278855d6957f5ed6ceefad41205a6ecc72ffbf Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Tue, 23 Mar 2021 11:07:19 -0700 Subject: [PATCH 2/3] Switch to camelCase functions --- pyqtgraph/colormap.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pyqtgraph/colormap.py b/pyqtgraph/colormap.py index 3d3c3188..88919e15 100644 --- a/pyqtgraph/colormap.py +++ b/pyqtgraph/colormap.py @@ -61,14 +61,14 @@ def get(name, source=None, skipCache=False): if not skipCache and name in _mapCache: return _mapCache[name] if source is None: - return _get_from_file(name) + return _getFromFile(name) elif source == 'matplotlib': - return _get_from_matplotlib(name) + return getFromMatplotlib(name) elif source == 'colorcet': - return _get_from_colorcet(name) + return getFromColorcet(name) return None -def _get_from_file(name): +def _getFromFile(name): filename = name if filename[0] !='.': # load from built-in directory dirname = path.dirname(__file__) @@ -114,7 +114,7 @@ def _get_from_file(name): _mapCache[name] = cm return cm -def _get_from_matplotlib(name): +def getFromMatplotlib(name): """ import colormap from matplotlib definition """ # inspired and informed by "mpl_cmaps_in_ImageItem.py", published by Sebastian Hoefer at # https://github.com/honkomonk/pyqtgraph_sandbox/blob/master/mpl_cmaps_in_ImageItem.py @@ -155,7 +155,7 @@ def _get_from_matplotlib(name): _mapCache[name] = cm return cm -def _get_from_colorcet(name): +def getFromColorcet(name): """ import colormap from colorcet definition """ try: import colorcet From bc7ca1beefe48dd46a97aa72148aaedc79015dc8 Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Tue, 23 Mar 2021 11:12:36 -0700 Subject: [PATCH 3/3] Move Color Map Example To Main Section --- examples/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/utils.py b/examples/utils.py index a7ac8bd6..a1223982 100644 --- a/examples/utils.py +++ b/examples/utils.py @@ -12,6 +12,7 @@ examples = OrderedDict([ ('Plot Customization', 'customPlot.py'), ('Timestamps on x axis', 'DateAxisItem.py'), ('Image Analysis', 'imageAnalysis.py'), + ('Color Maps', 'colorMaps.py'), ('ViewBox Features', Namespace(filename='ViewBoxFeatures.py', recommended=True)), ('Dock widgets', 'dockarea.py'), ('Console', 'ConsoleWidget.py'), @@ -102,7 +103,6 @@ others = dict([ ('DiffTreeWidget', 'DiffTreeWidget.py'), ('MultiPlotWidget', 'MultiPlotWidget.py'), ('RemoteGraphicsView', 'RemoteGraphicsView.py'), - ('colorMaps', 'colorMaps.py'), ('contextMenu', 'contextMenu.py'), ('designerExample', 'designerExample.py'), ('DateAxisItem_QtDesigner', 'DateAxisItem_QtDesigner.py'),