# 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
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,jpeg Before, tif [Could not display because file type unsupported...it looked very similar to the "before" jpeg] After, png After, jpeg After,tif [Could not display because file type unsupported...it looked very similar to the "after" jpeg]
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.
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.

Merged

Member

### pelson commented Apr 18, 2013

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

### dhyams commented Apr 18, 2013

 No, it's not. It's a separate 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?
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.
Member

### tacaswell commented Apr 18, 2013

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

### dhyams commented Apr 24, 2013

 I agree tacaswell.
 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.
 9192c2e 
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
 3b2a722 

### mdboom merged commit 3b2a722 into matplotlib:master May 13, 2013 1 check passed

#### 1 check passed

default The Travis build passed
Details

### dmcdougall referenced this pull request Jun 16, 2013

Closed

#### Subscripts and superscripts not saving in .tiff files #1877

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