-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Colorbar extend patches do not have correct alpha #22970
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
Comments
What happens if you do set_over and set_under? I actually think the behaviour of the Colorbar alpha matching the alpha of the image is questionable behaviour. |
I still get the inconsistent behaviour - transparent (alpha < 1) colorbar, non-transparent (alpha = 1) triangles - with set_over/set_under: import numpy as np
import matplotlib.pyplot as plt
img = np.random.rand(10, 10)
alpha = 0.3
cmap = plt.get_cmap('Greys').copy()
cmap.set_under('r')
cmap.set_over('b')
plt.imshow(img, alpha=alpha, cmap=cmap, vmin=0.25, vmax=0.75)
plt.colorbar(extend='both')
plt.show()
I think there are cases where each behaviour can be desirable, e.g. in the image above, the greys would probably be more difficult to understand if the colorbar wasn't transparent. Maybe there should be option when creating the colorbar to specify if it takes the image's alpha or just has alpha = 1? |
I've just tested this with an older conda environment and the colorbar and triangles have consistent alpha with matplotlib 3.4.3, so this appears to be an issue introduced in a recent update |
You can specify an RGBA fill in the over: I think the fix here is to add matplotlib/lib/matplotlib/colorbar.py Lines 729 to 735 in f8cd2c9
|
Yes, we definitely changed how the extents are handled. OTOH someone, at some point, went in and put plumbing in to change the Colorbar alpha to match the mappable alpha. I guess that's OK-ish if the the mappable has one alpha, but becomes meaningless if the mappable has multiple alphas (as an image can). Better in this case would be to make the colormap have an alpha. I'm not convinced that the original feature was that great. |
I agree. The colormap does already have an alpha, but it can be out of sync with the image here since the image/mappable has a different alpha. Sorting out how to get the colormap and image to keep their alpha's in-sync may be a bit of a bigger refactor though. I think the fix I put above is a minimal update to get this working again. |
Right, I guess I just think our API gets to be messy because of too many automatic hooks that then overlap in functionality. |
I would like to work on this. Is anyone working on it? |
@kkoutris Go for it! If there is not a linked PR it is safe to assume there is not active work going on. |
@tacaswell if you have the time, can you guide me a bit on what to change to fix this issue? |
@kkoutris #22970 (comment) basically says how to fix the issue. |
Since I don't see a PR, @kkoutris are you still working on this or could I pick up this issue? |
Uh oh!
There was an error while loading. Please reload this page.
Bug summary
When a colorbar has
extend != 'neither'
, the triangles at the end of the colorbar always havealpha=1
, even when the rest of the colorbar has a different alpha value.Code for reproduction
Actual outcome
Expected outcome
The triangles at the end of the colorbar should have the same alpha as the colorbar (i.e. roughly like the temporary fix above)
Additional information
No response
Operating system
OS/X
Matplotlib Version
3.5.2
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
Python 3.10.4
Jupyter version
No response
Installation
conda
The text was updated successfully, but these errors were encountered: