Skip to content

[Bug]: alpha array-type not working with RGB image in imshow() #26092

@patquem

Description

@patquem

Bug summary

Hi,
Whereas alpha = constant works with RGB image, this is not the case when working with an array-type for alpha.
(In my real case, I can only pass standard imshow parameters like alpha to the function of the library I use, and not a RGBA array).
Patrick

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
from skimage.color import gray2rgb

arr = np.random.random((10, 10))
arr_rgb = gray2rgb(arr)

alpha = np.ones_like(arr)
alpha[:5] = 0.2

plt.figure()
plt.tight_layout()
plt.subplot(121)
plt.title("Expected outcome")
plt.imshow(arr, alpha=alpha, cmap='gray')
plt.subplot(122)
plt.title("Actual outcome")
plt.imshow(arr_rgb, alpha=alpha)
plt.show()

Actual outcome

image

Expected outcome

image

Additional information

No response

Operating system

Windows

Matplotlib Version

3.7.1

Matplotlib Backend

TkAgg

Python version

Python 3.10.11

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions