Skip to content

[Bug]: imshow three channel image with pixelwise alpha parameter does not work #24333

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

Closed
Daraan opened this issue Nov 1, 2022 · 2 comments
Closed

Comments

@Daraan
Copy link

Daraan commented Nov 1, 2022

Bug summary

Using plt.imshow(B, alpha=alphas) where B has dimensions NxMx3 and alphas NxM ignores the the alpha parameter is silently ignored and B displayed as is.

Code for reproduction

import matplotlib as m
import matplotlib.pyplot as plt
import numpy as np

A=np.arange(5*5*3).reshape((5,5,3)) / (5*5*3)

plt.imshow(A)
plt.title("A")
plt.show()

B = np.zeros(5*5*3).reshape((5,3,5))
B[2:4, 2:4] = 1
B.shape = (5,5,3) # do some shifting so its not grayscale
plt.imshow(B)
plt.title("B")
plt.show()

alphas = np.zeros(5*5).reshape((5,5))
alphas[B[:,:,1] > 0] = 0.66
plt.imshow(alphas)
plt.title("Alpha mask")
plt.show()

plt.imshow(A)
plt.imshow(B, alpha=alphas) # gives wrong result
plt.title("wrong result")
plt.show()

Actual outcome

https://i.stack.imgur.com/6mHzi.png

Expected outcome

grafik

Additional information

Providing just a single alpha value or the alpha instead as alpha channel in B NxMx4 works.
But there is no warning to apply this fix or automatically merge it to apply the alpha channel as expected.

Operating system

linux and windows

Matplotlib Version

3.5.2 and 3.6.0

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

'3.9.7' and 3.10.6

Jupyter version

3.4.4

Installation

conda

@tacaswell
Copy link
Member

I think the fix is either to enrich the RGB to be RGBA in this case or to raise an exception if both alphas is set for non falescolor data. I can see arguments for both, but this is the worst of all options.

@tacaswell tacaswell added this to the v3.7.0 milestone Nov 1, 2022
@ksunden ksunden modified the milestones: v3.7.0, v3.7.1 Feb 14, 2023
@QuLogic QuLogic modified the milestones: v3.7.1, v3.7.2 Mar 4, 2023
@QuLogic QuLogic modified the milestones: v3.7.2, v3.7.3 Jul 5, 2023
@QuLogic QuLogic modified the milestones: v3.7.3, v3.8.0 Sep 9, 2023
@ksunden ksunden removed this from the v3.8.0 milestone Sep 15, 2023
@QuLogic
Copy link
Member

QuLogic commented Jan 4, 2024

This is a duplicate of #26092, which while newer, does seem to have a bit more discussion.

@QuLogic QuLogic closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants