Skip to content

more convenience methods for color maps and bars#2090

Merged
j9ac9k merged 9 commits intopyqtgraph:masterfrom
NilsNemitz:ColorMapAssignment
Nov 18, 2021
Merged

more convenience methods for color maps and bars#2090
j9ac9k merged 9 commits intopyqtgraph:masterfrom
NilsNemitz:ColorMapAssignment

Conversation

@NilsNemitz
Copy link
Copy Markdown
Contributor

@NilsNemitz NilsNemitz commented Nov 14, 2021

This is meant to address #2067.

The ImageItem false color options were initially completely designed around control through HistogramLUTItem.
This adds a setColorMap() method to ImageItem, and the option to use this through a colorMap argument during initialization, setImage() or setOpts().

The PR also adds the option to create and add a ColorBarItem through a new addColorBar() method of ImageItem.
This is somewhat inelegant, since the user needs to manually pass a reference to the plot. I could not find a means for the ImageItem to determine its parent. An alternative would have been to include addColorBar() as a method of the PlotItem, but this results in a circular import.

I have updated the ColorBarItem example to use the new methods for demonstration. The code to add an image with color map and interactive color bar is now down to just

i1 = pg.ImageItem(image=data)
p1.addItem( i1 )
p1.addColorBar( i1, colorMap='CET-L9', values=(0, 30_000))

Might close #2067 ...

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Nov 14, 2021

That cyclic import is going to be tough to work-around, unless you move the import of ColorBarItem into the addColorBar method; which, while ugly, might not be the worst idea.

"""
return self._colorMap

# def addColorBar(self, colorMap=None, plot=None, **kargs):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like just need to delete this commented out code and this is probably good to merge? I should take this diff for a spin myself first I suppose.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Nov 18, 2021

Thanks for all the documentation tidying! This LGTM, merging.

@j9ac9k j9ac9k merged commit 30d78fb into pyqtgraph:master Nov 18, 2021
ntjess pushed a commit to ntjess/pyqtgraph that referenced this pull request Dec 10, 2021
* more convenience methods for color maps and bars

* minor cleanup

* return ColorBarItem when added

* don't touch PlotItem

* move addColorBar to PlotItem

* wiggle initialization loops

* documentation pass

* add some more cross-references

* removed an unused line from example
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.

Enhancement: allow string or colormap to be passed to ImageItem directly

2 participants