Printing problems with "WXAgg" on Linux (minakawa)

From the traceback, it looks as if you are using the Wx backend, not the WxAgg

backend, and you are using "usetex" (text rendering using (La)TeX). The Wx
backend does not support usetex -- the WxAgg backend does. Check your
matplotlibrc or your matplotlib.use command and make sure you're selecting the
WxAgg backend.

Cheers,
Mike

hi Mike,
no it is WxAgg, the code is here:

···

-----
import wx
import os
import matplotlib
matplotlib.use('WxAgg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
from matplotlib.figure import Figure
import matplotlib.numerix as numpy

class PlotFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Test Printing with WX Backend")
        self.fig = Figure(None, 100)
        self.canvas= FigCanvas(self, -1, self.fig)
        self.axes = self.fig.add_axes([0.15,0.15,0.75,0.75])
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
        self.Fit()
        self.Plot_Data()

    def Print_Data(self):
        self.canvas.printerData.SetPaperId(wx.PAPER_A4)
        self.canvas.printerData.SetOrientation(wx.LANDSCAPE)
        dpi = self.canvas.figure.dpi.get()
        self.canvas.figure.dpi.set(200)
        self.canvas.Printer_Print()
        self.canvas.figure.dpi.set(dpi)
        self.canvas.draw()

    def Plot_Data(self):
        t = numpy.arange(0.0,5.0,0.01)
        s = numpy.sin(2.0*numpy.pi*t)
        c = numpy.cos(0.4*numpy.pi*t)
        self.axes.plot(t,s)
        self.axes.plot(t,c)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    fig = PlotFrame()
    fig.Show(True)
    fig.Print_Data()
    app.MainLoop()
---------------------

But you got a point with usetex : I set it to False and then no more traceback, though the preview indicates that LANDSCAPE mode was not applied.
So : WxAgg seems to have issues with usetex=True, and LANDSCAPE request does not seem to be honored... I am using svn revision 4797.

best, and happy New Year!
Johann

Michael Droettboom wrote:

From the traceback, it looks as if you are using the Wx backend, not the WxAgg backend, and you are using "usetex" (text rendering using (La)TeX). The Wx backend does not support usetex -- the WxAgg backend does. Check your matplotlibrc or your matplotlib.use command and make sure you're selecting the WxAgg backend.

Cheers,
Mike

Happy New Year to you as well!

I see now where part of the confusion lies -- even though you have specified the WxAgg backend, the Wx backend is being used for the printing. Though I didn't write this code, I assume this is by design -- WxAgg can only generate bitmaps, and we don't want to use those for printing. Unfortunately, Wx (non-Agg) has some limitations, as you've discovered. (For a list of the limitations, see http://matplotlib.sourceforge.net/backends.html). Given all those shortcomings, you may be better off generating a Postscript file and then send that to lpr. That should work on most modern Linux distributions even without a Postscript printer. You can do:

   savefig("foo.ps")

to use the matplotlib built-in Postscript backend.

As for your other questions -->

   1. You cannot set orientation to LANDSCAPE, it seems "SetOrientation" does not work.
   2. When you set LANDSCAPE manually, only lower half part will be printed.

I can't reproduce this. Your included example seems to produce correct LANDSCAPE pages for me. These are my relevant versions -- what are yours?

wxPython: 2.8.6.1
gtk+: 2.10.9
RHEL4

   3. Printing quality is far much worse than Windows's printing.

I can confirm that the Postscript generated by Wx is storing a bitmap, and not vector data. This is probably the source of the quality loss. I can't quite figure out why this is happening, but I have experienced similar problems with another Wx project. Perhaps that's an inherent limitation of Wx printing? In any case, it's a little bit below the level of matplotlib, so perhaps a question on the wxPython mailing list would help...

But my suggested workaround -- generating a Postscript file using matplotlib's built-in Postscript support, instead of the Wx printing framework -- and then printing that may be a better option for you.

Cheers,
Mike

Johann Cohen-Tanugi wrote:

···

hi Mike,
no it is WxAgg, the code is here:
-----
import wx
import os
import matplotlib
matplotlib.use('WxAgg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
from matplotlib.figure import Figure
import matplotlib.numerix as numpy

class PlotFrame(wx.Frame):
   def __init__(self):
       wx.Frame.__init__(self, None, -1, "Test Printing with WX Backend")
       self.fig = Figure(None, 100)
       self.canvas= FigCanvas(self, -1, self.fig)
       self.axes = self.fig.add_axes([0.15,0.15,0.75,0.75])
       sizer = wx.BoxSizer(wx.VERTICAL)
       sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
       self.Fit()
       self.Plot_Data()

   def Print_Data(self):
       self.canvas.printerData.SetPaperId(wx.PAPER_A4)
       self.canvas.printerData.SetOrientation(wx.LANDSCAPE)
       dpi = self.canvas.figure.dpi.get()
       self.canvas.figure.dpi.set(200)
       self.canvas.Printer_Print()
       self.canvas.figure.dpi.set(dpi)
       self.canvas.draw()

   def Plot_Data(self):
       t = numpy.arange(0.0,5.0,0.01)
       s = numpy.sin(2.0*numpy.pi*t)
       c = numpy.cos(0.4*numpy.pi*t)
       self.axes.plot(t,s)
       self.axes.plot(t,c)

if __name__ == '__main__':
   app = wx.PySimpleApp()
   fig = PlotFrame()
   fig.Show(True)
   fig.Print_Data()
   app.MainLoop()
---------------------

But you got a point with usetex : I set it to False and then no more traceback, though the preview indicates that LANDSCAPE mode was not applied.
So : WxAgg seems to have issues with usetex=True, and LANDSCAPE request does not seem to be honored... I am using svn revision 4797.

best, and happy New Year!
Johann

Michael Droettboom wrote:

From the traceback, it looks as if you are using the Wx backend, not the WxAgg backend, and you are using "usetex" (text rendering using (La)TeX). The Wx backend does not support usetex -- the WxAgg backend does. Check your matplotlibrc or your matplotlib.use command and make sure you're selecting the WxAgg backend.

Cheers,
Mike
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA