strange output from wx and wxagg when trying to render to JPEG or TIFF #1770

Merged
merged 1 commit into from May 13, 2013

Conversation

Projects
None yet
4 participants
@dhyams
Contributor

dhyams commented Feb 21, 2013

This patch has been tested under Windows, OSX, and Linux. If PIL is present, it gives an accurate rendering of the graph, whereas the wx backend's print_jpeg and print_tiff don't. I've attached before and after pictures (before and after this patch).

Other backends that might exhibit similar behavior, but I am not in a position to test, are:

  • gdk
  • gtk
  • macosx

A test script that generates the images is below.

#!/usr/bin/env python
import matplotlib
matplotlib.use('WxAgg')
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0.0,2.0*np.pi,50)
y = np.sin(x)  

plt.plot(x,y,color='red')
plt.title("Any text can have math: $E = m\sqrt{c^4}$")
plt.xlim(0.0,2.0*np.pi)


canvas = plt.gcf().get_canvas()
canvas.print_tiff('out.tif')
canvas.print_png('out.png')
canvas.print_jpeg('out.jpg')

plt.show()

Before, png
before
Before,jpeg
before
Before, tif
[Could not display because file type unsupported...it looked very similar to the "before" jpeg]

After, png
after

After, jpeg
after

After,tif
[Could not display because file type unsupported...it looked very similar to the "after" jpeg]

@mdboom

This comment has been minimized.

Show comment
Hide comment
@mdboom

mdboom Feb 21, 2013

Member

What's happening here is that for JPEG, TIF, etc., it's using the Wx, not the WxAgg backend for rendering (with all of the bugs associated with that backend). I think the true fix for this is to add a get_renderer method which would return a WxRenderer on Wx and an agg renderer on WxAgg and then use that from _print_image. This model is used in the Gtk/GtkAgg backends to great effect. This would allow for using the Agg renderer but wxWidgets file outputting code, thus not requiring PIL.

Member

mdboom commented Feb 21, 2013

What's happening here is that for JPEG, TIF, etc., it's using the Wx, not the WxAgg backend for rendering (with all of the bugs associated with that backend). I think the true fix for this is to add a get_renderer method which would return a WxRenderer on Wx and an agg renderer on WxAgg and then use that from _print_image. This model is used in the Gtk/GtkAgg backends to great effect. This would allow for using the Agg renderer but wxWidgets file outputting code, thus not requiring PIL.

@dhyams

This comment has been minimized.

Show comment
Hide comment
@dhyams

dhyams Feb 21, 2013

Contributor

Ah, I see. I didn't see the WxAgg specific print_png code...I'll look over things again and try to implement the fix that you recommend above.

Contributor

dhyams commented Feb 21, 2013

Ah, I see. I didn't see the WxAgg specific print_png code...I'll look over things again and try to implement the fix that you recommend above.

@pelson

This comment has been minimized.

Show comment
Hide comment
@pelson

pelson Apr 18, 2013

Member

Looks like this PR is superceeded by #1771. Is that correct? If so, please feel free to close.

Member

pelson commented Apr 18, 2013

Looks like this PR is superceeded by #1771. Is that correct? If so, please feel free to close.

@dhyams

This comment has been minimized.

Show comment
Hide comment
@dhyams

dhyams Apr 18, 2013

Contributor

No, it's not. It's a separate issue.

Contributor

dhyams commented Apr 18, 2013

No, it's not. It's a separate issue.

@dhyams

This comment has been minimized.

Show comment
Hide comment
@dhyams

dhyams Apr 18, 2013

Contributor

And I'm not sure that I am going to have a chance to sit down and figure out how to fix this as mdboom recommends...is there a way to formally express this pull request as an issue?

Contributor

dhyams commented Apr 18, 2013

And I'm not sure that I am going to have a chance to sit down and figure out how to fix this as mdboom recommends...is there a way to formally express this pull request as an issue?

@mdboom

This comment has been minimized.

Show comment
Hide comment
@mdboom

mdboom Apr 18, 2013

Member

I'm milestoning it as 1.3.x so we don't lose track of the underlying issue. If you or someone else (perhaps myself) submits an alternative PR, we can close this in favor of it then.

Member

mdboom commented Apr 18, 2013

I'm milestoning it as 1.3.x so we don't lose track of the underlying issue. If you or someone else (perhaps myself) submits an alternative PR, we can close this in favor of it then.

@tacaswell

This comment has been minimized.

Show comment
Hide comment
@tacaswell

tacaswell Apr 18, 2013

Member

This (on quick inspection) looks to be the same as issue #1877

Member

tacaswell commented Apr 18, 2013

This (on quick inspection) looks to be the same as issue #1877

@dhyams

This comment has been minimized.

Show comment
Hide comment
@dhyams

dhyams Apr 24, 2013

Contributor

I agree tacaswell.

Contributor

dhyams commented Apr 24, 2013

I agree tacaswell.

Daniel Hyams
wx backend should not attempt to render jpeg/tiff if PIL is present.
If PIL is present, the wx backend needs to allow the base class to get the
job done for print_jpeg and print_tiff, instead of trying to take over
duties itself.
@mdboom

This comment has been minimized.

Show comment
Hide comment
@mdboom

mdboom May 13, 2013

Member

@dhyams: Thanks, I think this is good to go. It requires #1998 to be merged first, however, to get past a show-stopping Wx bug.

Member

mdboom commented May 13, 2013

@dhyams: Thanks, I think this is good to go. It requires #1998 to be merged first, however, to get past a show-stopping Wx bug.

mdboom added a commit that referenced this pull request May 13, 2013

Merge pull request #1770 from dhyams/wxbackend_tiff_jpeg_pil_fix
strange output from wx and wxagg when trying to render to JPEG or TIFF

@mdboom mdboom merged commit 3b2a722 into matplotlib:master May 13, 2013

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment