-
Notifications
You must be signed in to change notification settings - Fork 590
Copy out of range colors to ScalarBars color LookupTable #6393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6393 +/- ##
=======================================
Coverage 97.41% 97.41%
=======================================
Files 143 143
Lines 27831 27833 +2
=======================================
+ Hits 27111 27113 +2
Misses 720 720 |
@tkoyama010 I suspect that the caching for the documentation is now broken. Are you able to clear the cache manually or increment the key in some way to invalidate it for future runs? Added: Otherwise we can use the |
I cleared the cache manually. If a similar problem occurs again in the future, let's deal with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your first contribution. We would like to add a test for this, so could you please provide the sample code that led you to find this bug?
I basically described this in the issue #6390 under "Steps to reproduce the bug". But I will provide a more concise example once I am back at my PC. |
Here is a minimal example that produces a visualization including a scalar bar with selected The code below explicitly calls import numpy as np
import pyvista as pv
# parameters
cmap = "viridis"
below_color = "magenta"
above_color = "red"
background_color = "cyan"
data = np.arange(10, dtype=float)
clim = [2.0, 8.0]
# create minimal DataSet
mesh = pv.PointSet(np.stack((data, np.zeros_like(data), np.zeros_like(data)), axis=-1))
mesh["Data"] = data
# visualization
plotter = pv.Plotter()
actor = plotter.add_mesh(
mesh,
clim=clim,
below_color=below_color,
above_color=above_color,
copy_mesh=True,
cmap=cmap,
show_scalar_bar=False,
)
scalar_bar = plotter.add_scalar_bar(
mapper=actor.mapper,
background_color=background_color,
fill=True,
outline=True,
)
# compare out of range colors for the actors and the scalar bar
scalar_bar_lut = scalar_bar.GetLookupTable()
assert actor.mapper.lookup_table.below_range_color == scalar_bar_lut.below_range_color
assert actor.mapper.lookup_table.above_range_color == scalar_bar_lut.above_range_color
# plotter.show() |
It occured to be that simply copying the out of range colors from the mapper lookuptable to the colorbar lookuptable might be too simple of a fix. pyvista/pyvista/plotting/scalar_bars.py Lines 440 to 447 in ac75644
could be desirable, e.g.: below_alpha = mapper_lut.below_range_color.opacity / 255
below_color = np.array(mapper_lut.below_range_color.int_rgba)
below_color[-1] = 255
background_color = np.array(background_color.int_rgba)
scalar_bar_lut.below_range_color = Color(
(below_alpha * below_color + (1 - below_alpha) * background_color).astype(int)
) I will update my feature branch to incorporate this additional logic, if that is okay. The test code snippet provided in my previous comment would still hold for opaque out of range colors. |
I looked some further into this as the following was unclear to me:
First of all, L446 has no effect on opaque scalar bars, only transparent ones. Furthermore, any transparent ScalarBar will naturally blend with the background during rendering, making L446 effectively irrelevant, unless This leads us to the edge case of Therefore, my question would be:
|
Thank you for your contribution. This is a great analysis of what should be expected from user inputs and the behaviour of the plots. I am not knowledgable enough about the scalar bars to properly respond, but L446 was last modified 3 years ago as part of b3362c2, it's quite possible that there are gaps in the testing and/or implementation. This comment suggests that there is/was missing test coverage.
A good way to figure this out is to systematically write test cases (e.g. in test_scalar_bars.py or test_plotting.py) with the user inputs and expected outputs. Any tests that fail would likely provide an answer to these questions. Or if there are problems/inconsistencies with the API feel free to suggest improvements. Let us know how if there's anything we can do to help. |
Overview
Correction to the way the color
LookupTable
(LUT) is tranfered from the actor/mappable to theScalarBars
, when bothbackground_color
andbelow_range_color
and/orabove_range_color
are specified.resolves #6390
Details
below_range_color
andabove_range_color
to the scalar bar color LookupTable inScalarBars.add_scalar_bar()
, asLookupTable.DeepCopy(...)
[presumably] only handles the underlying VTK implementation.