Skip to content

make ColorBarItem agnostic of the image kind#2879

Merged
j9ac9k merged 6 commits intopyqtgraph:masterfrom
pijyoi:unify-cmap-lut
Nov 12, 2023
Merged

make ColorBarItem agnostic of the image kind#2879
j9ac9k merged 6 commits intopyqtgraph:masterfrom
pijyoi:unify-cmap-lut

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Nov 12, 2023

This PR seeks to make the support of ColorBarItem for the various image-like GraphicsItems more consistent.

It changes ColorBarItem to update the image-like items under its control using setColorMap instead of setLookupTable.

It also tries to make NonUniformImage and 'PColorMeshIteminternally more consistent when bothsetColorMapandsetLookupTable` have been used.

Script to test that setting colormap from ColorBarItem propagates to the various image-like items.

import random

import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore
from pyqtgraph.graphicsItems.NonUniformImage import NonUniformImage

pg.mkQApp()
glw = pg.GraphicsLayoutWidget()
glw.show()

rng = np.random.default_rng(12345)
Z = rng.standard_normal(size=(50, 30))
x = np.arange(Z.shape[0])
y = np.arange(Z.shape[1])

images = []
images.append(pg.ImageItem(Z))
images.append(NonUniformImage(x, y, Z))
images.append(pg.PColorMeshItem(Z))

titles = ['Image', 'NonUniform', 'PColorMesh']
views = []
for idx, title in enumerate(titles):
    view = glw.addPlot(idx, 0, 1, 1, title=title)
    view.addItem(images[idx])
    views.append(view)

cbar = pg.ColorBarItem(colorMap='cividis', interactive=False)
cbar.setImageItem(images)
glw.addItem(cbar, 0, 1, 3, 1)

colormaps = pg.colormap.listMaps()

def update():
    # setting colormap on ColorBarItem propagates to all images
    cmap = pg.colormap.get(random.choice(colormaps))
    cbar.setColorMap(cmap)

timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(250)

pg.exec()

lut no longer has precedence over cmap.
whichever got set last wins.
cmap as an argument was previously deprecated.
after the deprecation cycle had expired, the deprecation warning was
removed but not the argument itself.
don't use the deprecated code path
@pijyoi pijyoi marked this pull request as ready for review November 12, 2023 08:53
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Nov 12, 2023

Love this diff @pijyoi thanks for the PR

@j9ac9k j9ac9k merged commit 4de3bf9 into pyqtgraph:master Nov 12, 2023
@pijyoi pijyoi deleted the unify-cmap-lut branch November 12, 2023 20:31
@pijyoi pijyoi mentioned this pull request Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants