From f1de464c460e9cbdb0987a4cf85b76930e88ad18 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Wed, 4 Oct 2017 08:30:38 -0700 Subject: [PATCH] Preserve levels when switching between mono and rgba modes --- pyqtgraph/graphicsItems/HistogramLUTItem.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pyqtgraph/graphicsItems/HistogramLUTItem.py b/pyqtgraph/graphicsItems/HistogramLUTItem.py index 68448c11..019fa3a7 100644 --- a/pyqtgraph/graphicsItems/HistogramLUTItem.py +++ b/pyqtgraph/graphicsItems/HistogramLUTItem.py @@ -288,9 +288,21 @@ class HistogramLUTItem(GraphicsWidget): Options are 'mono' or 'rgba'. """ assert mode in ('mono', 'rgba') + + oldLevels = self.getLevels() + self.levelMode = mode self._showRegions() self.imageChanged() + + # do our best to preserve old levels + if mode == 'mono': + levels = np.array(oldLevels).mean(axis=0) + self.setLevels(*levels) + else: + levels = [oldLevels] * 4 + self.setLevels(rgba=levels) + self.update() def _showRegions(self):