Skip to content
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

imshow(..., alpha=0.5) produces different results in 2.x #6540

Closed
QuLogic opened this issue Jun 6, 2016 · 4 comments
Closed

imshow(..., alpha=0.5) produces different results in 2.x #6540

QuLogic opened this issue Jun 6, 2016 · 4 comments
Assignees
Milestone

Comments

@QuLogic
Copy link
Member

QuLogic commented Jun 6, 2016

I think I have whittled this down sufficiently from the Cartopy example that is failing. Running imshow(..., alpha=0.5) produces a different result in 2.0.0b1 vs. 1.5.1 (both installed via conda.)

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

# mpl.style.use('classic')

im = np.zeros((100, 100, 3), dtype=np.uint8)
plt.imshow(im, extent=(1, 10, 1, 10), alpha=0.5)
plt.xlim(0, 11)
plt.ylim(0, 11)

plt.savefig('imshow_alpha.png')

Using 1.5.1:
imshow_alpha_1 5 1
Using 2.0.0b1:
imshow_alpha_2 0
Using 2.0.0b1 with the classic style:
imshow_alpha_2 0_classic

GIMP tells me that the first is 50%, while the latter two are 75%.

@QuLogic QuLogic added this to the 2.0 (style change major release) milestone Jun 6, 2016
@WeatherGod
Copy link
Member

@mdboom, is this a result of the image architecture overhaul?

On Mon, Jun 6, 2016 at 1:47 AM, Elliott Sales de Andrade <
notifications@github.com> wrote:

I think I have whittled this down sufficiently from the Cartopy example
that is failing. Running imshow(..., alpha=0.5) produces a different
result in 2.0.0b1 vs. 1.5.1 (both installed via conda.)

import numpy as npimport matplotlib.pyplot as pltimport matplotlib as mpl

mpl.style.use('classic')

im = np.zeros((100, 100, 3), dtype=np.uint8)
plt.imshow(im, extent=(1, 10, 1, 10), alpha=0.5)
plt.xlim(0, 11)
plt.ylim(0, 11)

plt.savefig('imshow_alpha.png')

Using 1.5.1:
[image: imshow_alpha_1 5 1]
https://cloud.githubusercontent.com/assets/302469/15812915/443b626e-2b88-11e6-89ca-14c0afbf4648.png
Using 2.0.0b1:
[image: imshow_alpha_2 0]
https://cloud.githubusercontent.com/assets/302469/15812917/4d8bc746-2b88-11e6-8e9f-68a37cd456d6.png
Using 2.0.0b1 with the classic style:
[image: imshow_alpha_2 0_classic]
https://cloud.githubusercontent.com/assets/302469/15812919/543d038e-2b88-11e6-9607-e80ae97955f6.png

GIMP tells me that the first is 50%, while the latter two are 75%.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#6540, or mute the thread
https://github.com/notifications/unsubscribe/AARy-NGkkXjrVwUIRPMnkrtSrR4Cnj66ks5qI7RogaJpZM4IulFm
.

@WeatherGod
Copy link
Member

I would be curious to know how the result compares with output from
gtkcairo.

On Tue, Jun 7, 2016 at 11:32 AM, Benjamin Root ben.v.root@gmail.com wrote:

@mdboom, is this a result of the image architecture overhaul?

On Mon, Jun 6, 2016 at 1:47 AM, Elliott Sales de Andrade <
notifications@github.com> wrote:

I think I have whittled this down sufficiently from the Cartopy example
that is failing. Running imshow(..., alpha=0.5) produces a different
result in 2.0.0b1 vs. 1.5.1 (both installed via conda.)

import numpy as npimport matplotlib.pyplot as pltimport matplotlib as mpl

mpl.style.use('classic')

im = np.zeros((100, 100, 3), dtype=np.uint8)
plt.imshow(im, extent=(1, 10, 1, 10), alpha=0.5)
plt.xlim(0, 11)
plt.ylim(0, 11)

plt.savefig('imshow_alpha.png')

Using 1.5.1:
[image: imshow_alpha_1 5 1]
https://cloud.githubusercontent.com/assets/302469/15812915/443b626e-2b88-11e6-89ca-14c0afbf4648.png
Using 2.0.0b1:
[image: imshow_alpha_2 0]
https://cloud.githubusercontent.com/assets/302469/15812917/4d8bc746-2b88-11e6-8e9f-68a37cd456d6.png
Using 2.0.0b1 with the classic style:
[image: imshow_alpha_2 0_classic]
https://cloud.githubusercontent.com/assets/302469/15812919/543d038e-2b88-11e6-9607-e80ae97955f6.png

GIMP tells me that the first is 50%, while the latter two are 75%.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#6540, or mute the
thread
https://github.com/notifications/unsubscribe/AARy-NGkkXjrVwUIRPMnkrtSrR4Cnj66ks5qI7RogaJpZM4IulFm
.

@QuLogic
Copy link
Member Author

QuLogic commented Jun 8, 2016

I tried GTK3Cairo, but it's current broken:

Traceback (most recent call last):
  File ".../lib/matplotlib/backends/backend_gtk3cairo.py", line 45, in on_draw_event
    self._render_figure(w, h)
  File ".../lib/matplotlib/backends/backend_gtk3cairo.py", line 34, in _render_figure
    self.figure.draw (self._renderer)
  File ".../lib/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File ".../lib/matplotlib/figure.py", line 1129, in draw
    renderer, self, dsu, self.suppressComposite)
  File ".../lib/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File ".../lib/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File ".../lib/matplotlib/axes/_base.py", line 2373, in draw
    mimage._draw_list_compositing_images(renderer, self, dsu)
  File ".../lib/matplotlib/image.py", line 163, in _draw_list_compositing_images
    flush_images()
  File ".../lib/matplotlib/image.py", line 147, in flush_images
    image_group[0].draw(renderer)
  File ".../lib/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File ".../lib/matplotlib/image.py", line 472, in draw
    renderer.draw_image(gc, l, b, im)
  File ".../lib/matplotlib/backends/backend_cairo.py", line 180, in draw_image
    im.shape[1]*4)
TypeError: expected a writeable buffer object

@tacaswell
Copy link
Member

It looks like alpha is getting double applied?

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jun 8, 2016
The alpha of the image pixels is folded in as part of the image
rendering process, it does not need to be done a second time in the gc.

Fixes matplotlib#6540
@tacaswell tacaswell self-assigned this Jun 8, 2016
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

3 participants