# matplotlib/matplotlib

### Subversion checkout URL

You can clone with
or
.

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

Merged
merged 1 commit into from
+9 −6

### 4 participants

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]

Owner

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.

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.

referenced this pull request
Merged

### Jpeg quality 95 by default with rendering with PIL #1771

Collaborator

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

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

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?

Owner

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.

Owner

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

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. 9192c2e
Owner

@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.

merged commit 3b2a722 into matplotlib:master

#### 1 check passed

Details default The Travis build passed
referenced this pull request
Closed

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

If PIL is present, the wx backend needs to allow the base class to get the
duties itself.