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

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

dhyams
Copy link
Contributor

@dhyams 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
Copy link
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
Copy link
Contributor Author

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
Copy link
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
Copy link
Contributor Author

dhyams commented Apr 18, 2013

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

@dhyams
Copy link
Contributor Author

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
Copy link
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
Copy link
Member

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

@dhyams
Copy link
Contributor Author

dhyams commented Apr 24, 2013

I agree tacaswell.

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
Copy link
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants