Skip to content

[Bug]: image alpha re-applied each draw? #29891

Closed

Description

@rcomer

Bug summary

On main, if I plot an RGBA image and then mess about with the gui window size, the image keeps getting darker.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)
rgba = np.random.random((2, 2, 4))

fig, ax = plt.subplots()

ax.imshow(rgba)

plt.show()

Actual outcome

After resizing the window a lot

Image

Expected outcome

Image

Additional information

Bisects to #29776 (cc @anntzer)

The problem is specific to RGBA - I noticed it first with the code from #26092 (comment), where only the top two plots of the righthand column are affected.

Operating system

RHEL9

Matplotlib Version

main

Matplotlib Backend

qtagg

Python version

3.12.7

Jupyter version

n/a

Installation

git checkout

Activity

  1. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Apr 9, 2025
  2. added this to the v3.11.0 milestone on Apr 9, 2025
  3. changed the title [-][Bug]: image alpha blending re-applied each draw?[/-] [+][Bug]: image alpha re-applied each draw?[/+] on Apr 9, 2025
  4. rcomer commented on Apr 9, 2025

    @rcomer
    MemberAuthor

    I think it's because for RGBA we are multiplying the original array here, but I am way out of my depth...

    A[..., :3] *= A[..., 3:]

  5. dstansby commented on Apr 9, 2025

    @dstansby
    Member

    This bisects to 27cb5e3

  6. dstansby commented on Apr 9, 2025

    @dstansby
    Member

    Which is consistent with your instict that it's that line that's caused the issue

  7. dstansby commented on Apr 9, 2025

    @dstansby
    Member

    Undoing the in-place multiplication by putting a A[..., :3] /= A[..., 3:] after the resample line fixes this, so I think you're definitely correct about what's causing it. I'm not sure if adding that line is the best fix or not though.

  8. rcomer commented on Apr 9, 2025

    @rcomer
    MemberAuthor

    @dstansby thanks! I have started a branch, so will put up a PR soon and we can hash it out :-)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.topic: images

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions