Skip to content

Conversation

@FazeelUsmani
Copy link
Contributor

@FazeelUsmani FazeelUsmani commented Nov 28, 2025

Closes #26092

This fix makes array alpha behavior consistent with scalar alpha behavior for RGBA images. Now both scalar and array alpha values multiply with the existing alpha channel rather than replacing it.

What is the reasoning for this implementation?

  • For RGB images (no existing alpha): array alpha is used directly as the alpha channel (unchanged behavior)
  • For RGBA images (has existing alpha): array alpha now multiplies with existing alpha (previously it replaced it)

This matches the existing scalar alpha behavior and provides more intuitive compositing.

Example

  import numpy as np
  import matplotlib.pyplot as plt

  # RGBA image with 50% alpha
  rgba = np.zeros((10, 10, 4), dtype=np.float32)
  rgba[:, :, 0] = 1.0  # Red
  rgba[:, :, 3] = 0.5  # 50% alpha

  # Array alpha
  alpha_arr = np.ones((10, 10))
  alpha_arr[:5] = 0.5

  # Before: top=0.5, bottom=1.0 (replaced)
  # After:  top=0.25, bottom=0.5 (multiplied)
  plt.imshow(rgba, alpha=alpha_arr)

PR checklist

  • "closes [Bug]: alpha array-type not working with RGB image in imshow() #26092" is in the body of the PR description
  • new and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • New Features and API Changes are noted with a directive and release note
  • [N/A] Documentation complies with general and docstring guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant