PColorMeshItem colorbar support#2477
Conversation
…scaling during animation.
…s `colorMap` and `limit`
…onvention in ImageItem and ColorBarItem
Add enableAutoLevels parameter to PColorMeshItem and autoLevels parameter to PColorMeshItem.setData() in order to conform with known APIs from ViewBox and ImageItem
Fix typos and improve code quality
Experimental first draft of ColorBar support in PColorMeshItem. Working prototype, but has flawed implementation that always disables autoLevels (autoscaling of colors) when the colorbar is added. Documentation is copied from ImageItem and has not been modified at all yet.
Add consistent logic for when ColorBarItem is in control of PColorMeshItem's levels, and the other way around. Add a separate plot in examples/PColorMeshItem.py to showcase both dynamic/autoscaling colorbars and static/consistent colorbars in the same example.
Fix conflicting name between method and variable
Remove an unnecessary TODO comment (based on a mixup between colormap and LUT)
|
@outofculture @j9ac9k |
|
Is there anything I can do to make this PR more reviewable? Is there some other platform I should have used to ask these questions to make sure I'm on the right track? Thanks |
|
Hi there @SimenZhor Sorry I've been quiet. I am on vacation with very limited internet connectivity. I'll be back in a few days and will review this PR more closely with @outofculture |
|
I have a few comments from a far-away perspective:
I also have the impression that this PR may change the defaults on ColorBarItem a little too far in the direction of the "animated image" use case. As far as I can tell, there are actually three typical uses: I think (2) might be the most common use case, and it is also what we traditionally seemed to be optimizing for. And as a bonus challenge, since we are probably not doing that correctly at this time: |
|
Hi @NilsNemitz, thanks for the thoughtful comments. I'll try my best to answer your questions.
If you mean in the example code, I just wanted to show that it is possible to enable and disable autoscaling, and intuitively illustrate how much of an effect this can make in a case like what the example was already showing:
Yeah, I kind of agree. I just didn't like the thought of repeating the same loop twice just to avoid this. I'll see if I can find another solution.
This is actually not entirely the same case as the change in colormap prioritization.
I have not (intentionally) changed the defaults of ColorBarItem other than the, already mentioned, colormap prioritization which is changed from first to last image in the supplied list.
There is a fourth use case, which I'd argue is quite commonly needed for animated images (I agree that usecase (2) will be the most common for still images). (4) Plot an image, keep the current scaling, do not allow interaction to manually change it. This usecase was the whole rationale behind the, already mentioned, PR where
That was my intention at least, but I realize now that I may have misunderstood your three usecases slightly. I guess I may have forgot to account for the "middle state" between plotting a single image and plotting an animation, which is reusing the same "static image" plot for a new, totally unrelated, static image that doesn't need to be compared with the previous dataset. I'd have to play around a bit with that to see how it would work.
Yes, I totally agree. This is what I attempted to solve with the |
|
@SimenZhor , I think you got all the points I was trying to make 👍 Sorry about getting the example mixed up with the main code, I totally withdraw that objection. |
ColorBarItem will pick a colormap from the "first and best" assigned image in cases where the ColorBarItem does not have a colormap explicitly assigned.
…isable auto-scaling Remove logic that made ColorBarItem attempt to disable auto-scaling for its assigned image items. This should instead be done manually by the user.
|
@NilsNemitz @j9ac9k Sorry for taking such a long time to finish this PR. I think I've now made the requested changes from Nils' earlier comment, except that I've not reverted the change of the variable named Regarding this comment:
The reason that So, I think I'll finally change this PR from draft to ready for review. |
|
Bah, I just introduced some merge conflicts for you @SimenZhor if you'd be fine with it, I don't mind resolving them on my end. |
|
No problem @j9ac9k, I’ve been following the dataBounds development as I ran into that issue myself a few weeks ago, so I think I’ll be able to sort out the conflicts some time next week. That being said, I don’t mind at all if you have time to look at it before that. |
If I'm itching to do a release before you get to it, I'll be sure to patch the conflicts myself first 😆 |
|
@j9ac9k The merge conflicts should now be resolved |
|
Thanks for the PR @SimenZhor This LGTM, thanks for reviewing @NilsNemitz Merging! |

This PR is a draft that I'm submitting to discuss a couple of problems I'm unsure if I've handled correctly.
First of all, this PR adds the basic API functionality to
PColorMeshItemthat is necessary to support forColorBarItem. However, I've found it necessary to extendColorBarItema bit in order to facilitate meaningful behavior with animations. The main problem being how to handle animated plots with autoscaling colors.As far as I can tell, there is currently no support for this in
ColorBarItem. If an image decides to scale it's colors as new data comes in, the colorbar will automatically become outdated. The way I've solved this is by adding a signal thatPColorMeshItemcan use to notifyColorBarItemthat it has changed its values, so that theColorBarItemcan update accordingly. For high FPS animations this can look quite messy, but what good is a colorbar if it's displaying the wrong information? Anyway: I've so far only implemented this signal inPColorMeshItembecause I want to hear some thoughts on this idea before potentially expandingImageItemas well.There are a couple of other headaches as well that relate to autoscaling colormaps. Mainly, how to prioritize parameters that represent the same thing but are supplied to different objects. For example, PColorMeshItems
levelsparameter means the same as ColorBarItemsvalues. What I've come up with is this order of priority:valuesparameter (if supplied by user)levelsparameter (if supplied by user)(0,1)This feels in line with how the colormap is already prioritized (although it does not have the "if supplied by user" clause on bulletpoint 2, removing the need for bulletpoint 3). It does however become more complex when you throw autoscaling into the mix. So for autoscaling I've implemented the following logic:
Is
ColorBarIteminteractive?disableAutoScaling()(only supported byPColorMeshItemso far)sigLevelsChangedsignalFinally, I've removed the
break-clause fromColorBarItem.setImageItem(), which will change behavior from selecting colormap from the first item to selecting from the last item. I realize this may be controversial, so I'm open to changing it back.