Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

## matplotlib-users

 [Matplotlib-users] QTagg, Latex, Label problem From: Gerhard Spitzlsperger - 2007-02-06 18:29:00 Dear All, I am new to matplotlib and playing around with it. I am interested in embedding in Qt, displaying TeX within such a window and finally save the plot as postscript. So I modified the embedding_in_qt example and added at the beginning rc('text', usetex=True) to prepare for TeX and modified the (according agg_oo example): def compute_initial_figure(self): t = arange(0.0, 3.0, 0.01) s = sin(2*pi*t) self.axes.set_ylabel(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!", fontsize=16, color='r') self.axes.set_xlabel("label") self.axes.plot(t, s) #self.print_figure("test.eps") function, to create labels (with TeX) but they are not displayed. Additionally if I include self.print_figure("test.eps") File "embedding_in_qt.py", line 67, in compute_initial_figure self.print_figure("test.eps") File "D:\APPS\PYTON2~1\Lib\site-packages\matplotlib\backends\backend_qtagg.py", line 159, in print_figure agg = self.switch_backends( FigureCanvasAgg ) File "D:\APPS\PYTON2~1\Lib\site-packages\matplotlib\backend_bases.py", line 944, in switch_backends newCanvas = FigureCanvasClass(self.figure) AttributeError: figure I am on WindowsXP, python 2.3.5 and matplotlib 0.87.6 The complete example is below. Thank you very much gerhard import sys, os, random from qt import * from matplotlib import rc from matplotlib.numerix import arange, sin, pi from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure rc('text', usetex=True) # This seems to be what PyQt expects, according to the examples shipped in # its distribution. TRUE = 1 FALSE = 0 progname = os.path.basename(sys.argv[0]) progversion = "0.1" # Note: color-intensive applications may require a different color allocation # strategy. QApplication.setColorSpec(QApplication.NormalColor) app = QApplication(sys.argv) class MyMplCanvas(FigureCanvas): """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.).""" def __init__(self, parent=None, width=5, height=4, dpi=100): self.fig = Figure(figsize=(width, height), dpi=dpi) self.axes = self.fig.add_subplot(111) # We want the axes cleared every time plot() is called self.axes.hold(False) self.compute_initial_figure() FigureCanvas.__init__(self, self.fig) self.reparent(parent, QPoint(0, 0)) FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) def sizeHint(self): w, h = self.get_width_height() return QSize(w, h) def minimumSizeHint(self): return QSize(10, 10) def compute_initial_figure(self): t = arange(0.0, 3.0, 0.01) s = sin(2*pi*t) self.axes.set_ylabel(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!", fontsize=16, color='r') self.axes.set_xlabel("label") self.axes.plot(t, s) #self.print_figure("test.eps") class ApplicationWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self, None, "application main window", Qt.WType_TopLevel | Qt.WDestructiveClose) self.file_menu = QPopupMenu(self) self.file_menu.insertItem('&Quit', self.fileQuit, Qt.CTRL + Qt.Key_Q) self.menuBar().insertItem('&File', self.file_menu) self.help_menu = QPopupMenu(self) self.menuBar().insertSeparator() self.menuBar().insertItem('&Help', self.help_menu) self.help_menu.insertItem('&About', self.about) self.main_widget = QWidget(self, "Main widget") l = QVBoxLayout(self.main_widget) sc = MyMplCanvas(self.main_widget, width=5, height=4, dpi=100) l.addWidget(sc) self.main_widget.setFocus() self.setCentralWidget(self.main_widget) self.statusBar().message("All hail matplotlib!", 2000) def fileQuit(self): qApp.exit(0) def closeEvent(self, ce): self.fileQuit() def about(self): QMessageBox.about(self, "About %s" % progname, u"""%(prog)s version %(version)s Copyright \N{COPYRIGHT SIGN} 2005 Florent Rougon This program is a simple example of a Qt application embedding matplotlib canvases. It may be used and modified with no restriction; raw copies as well as modified versions may be distributed without limitation.""" % {"prog": progname, "version": progversion}) def main(): aw = ApplicationWindow() aw.setCaption("%s" % progname) qApp.setMainWidget(aw) aw.show() sys.exit(qApp.exec_loop()) if __name__ == "__main__": main() -- Gerhard Spitzlsperger Renesas Semiconductor Europe (Landshut) GmbH Senior Advisor Process Jenaer Strasse 1 Germany 84034 Landshut Tel +(49) 871 684 342 Fax +(49) 871 684 150 ----------------------------------------- The road goes ever on and on down from the door where it began. Now far ahead the road has gone, and I must follow, if I can **************************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. Access to this e-mail by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited. E-mail messages are not necessarily secure. Renesas does not accept responsibility for any changes made to this message after it was sent. Please note that this email message has been swept by Renesas for the presence of computer viruses. **************************************************************************** 
 Re: [Matplotlib-users] QTagg, Latex, Label problem From: Darren Dale - 2007-02-06 18:58:03 Attachments: EmbeddingInQt_UseTeX.py On Tuesday 06 February 2007 01:28:10 pm Gerhard Spitzlsperger wrote: > I am new to matplotlib and playing around with it. I am interested in > embedding in Qt, displaying TeX within such a window and finally > save the plot as postscript. [...] > and modified the (according agg_oo example): > > def compute_initial_figure(self): [...] > function, to create labels (with TeX) but they are not displayed. The example you posted works fine for me. Are you sure you have installed and properly configured all the required external dependencies? See http://www.scipy.org/Cookbook/Matplotlib/UsingTex for more details. > Additionally if I include self.print_figure("test.eps") > > File "embedding_in_qt.py", line 67, in compute_initial_figure > self.print_figure("test.eps") > File > "D:\APPS\PYTON2~1\Lib\site-packages\matplotlib\backends\backend_qtagg.py", > line 159, in print_figure > agg = self.switch_backends( FigureCanvasAgg ) > File > "D:\APPS\PYTON2~1\Lib\site-packages\matplotlib\backend_bases.py", line > 944, in switch_backends > newCanvas = FigureCanvasClass(self.figure) > AttributeError: figure Your class MyMplCanvas needs a figure attribute. Change all self.fig references to self.figure (see attached). Darren 
 Re: [Matplotlib-users] QTagg, Latex, Label problem From: Gerhard Spitzlsperger - 2007-02-07 08:17:19 Hallo Darren, thank you very much Darren Dale schrieb: >>embedding in Qt, displaying TeX within such a window and finally >>save the plot as postscript. > ... >>function, to create labels (with TeX) but they are not displayed. > > > The example you posted works fine for me. Are you sure you have installed and > properly configured all the required external dependencies? See > http://www.scipy.org/Cookbook/Matplotlib/UsingTex for more details. > I guess I installed correctly as the standard examples provided with matplotlib work as expected. Also if I remove all TeX related stuff and just place the following line in the original "embedding_in_qt.py" function compute_initial_figure: self.axes.set_xlabel("label") the label is not displayed. On another machine WindowsXP, Qt4 python 2.4.3 and matplotlib 0.87.7 I experience the same problem self.axes.set_xlabel("label") added to compute_initial_figure in "embedding_in_qt4.py" doesn't display a label (embedding in tk works as expected on both machines). >>Additionally if I include self.print_figure("test.eps") >> ... > > > Your class MyMplCanvas needs a figure attribute. Change all self.fig > references to self.figure (see attached). > Thank you very much this works (but also the postscript output does not display the label). (BTW during playing I recogized maybe a small issue in backend_qt4agg line 152 in print_figure if arg dpi is None matplotlib.rcParams is accessed but matplotlib.rcParams is not imported) Regards Gerhard -- Gerhard Spitzlsperger Renesas Semiconductor Europe (Landshut) GmbH Senior Advisor Process Jenaer Strasse 1 Germany 84034 Landshut Tel +(49) 871 684 342 Fax +(49) 871 684 150 ----------------------------------------- The road goes ever on and on down from the door where it began. Now far ahead the road has gone, and I must follow, if I can **************************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. Access to this e-mail by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited. E-mail messages are not necessarily secure. Renesas does not accept responsibility for any changes made to this message after it was sent. Please note that this email message has been swept by Renesas for the presence of computer viruses. **************************************************************************** 
 Re: [Matplotlib-users] QTagg, Latex, Label problem From: Darren Dale - 2007-02-07 13:25:45 On Wednesday 07 February 2007 03:17:06 am Gerhard Spitzlsperger wrote: > Hallo Darren, > > thank you very much > > Darren Dale schrieb: > >>embedding in Qt, displaying TeX within such a window and finally > >>save the plot as postscript. > > ... > > >>function, to create labels (with TeX) but they are not displayed. > > > > The example you posted works fine for me. Are you sure you have installed > > and properly configured all the required external dependencies? See > > http://www.scipy.org/Cookbook/Matplotlib/UsingTex for more details. > > I guess I installed correctly as the standard examples provided > with matplotlib work as expected. To which examples are you referring? The usetex example? > Also if I remove all TeX related stuff and just place the following line > in the original "embedding_in_qt.py" function compute_initial_figure: > > self.axes.set_xlabel("label") > > the label is not displayed. You disable usetex, and your text is not being rendered. Is that correct? If so, the problem has nothing to do with the LaTeX layout engine. I suggest writing the shortest possible example that illustrates the problem (your previous example is obviously too complex, since the label is not rendered even without usetex enabled), run it with your rc.verbose.level set to debug, and post again. Darren 
 Re: [Matplotlib-users] QTagg, Latex, Label problem From: Gerhard Spitzlsperger - 2007-02-15 10:04:23 Hallo Darren, thank you for your support, it seems I made a simple mistake >>in the original "embedding_in_qt.py" function compute_initial_figure: >> >>self.axes.set_xlabel("label") >> >>the label is not displayed. > > I placed the "self.axes.set_xlabel("label")" before the self.axes.plot. if order is changed everything works as expected. Thank you Gerhard -- Gerhard Spitzlsperger Renesas Semiconductor Europe (Landshut) GmbH Senior Advisor Process Jenaer Strasse 1 Germany 84034 Landshut Tel +(49) 871 684 342 Fax +(49) 871 684 150 ----------------------------------------- The road goes ever on and on down from the door where it began. Now far ahead the road has gone, and I must follow, if I can **************************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. Access to this e-mail by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited. E-mail messages are not necessarily secure. Renesas does not accept responsibility for any changes made to this message after it was sent. Please note that this email message has been swept by Renesas for the presence of computer viruses. Renesas Semiconductor Europe (Landshut) GmbH Jenaer Strasse 1, 84034 Landshut Tel.: +49-(0)871-684-0, Fax: +49-(0)871-684-150 http://www.rsel.renesas.com GESCHAEFTSFUEHRER: Dipl.-Ing. YOSHIHARU KAKUI Dipl.-Phys. STEFAN SAUER Registergericht Landshut HRB 1464 Ust-ldNr.: DE 128953054 Steuer-Nr.: 132/136/30347 HypoVereinsbank, Landshut, Kto.-Nr. 3704 700 (BLZ 743 200 73) Mizuho Corporate Bank (Germany) AG, Frankfurt, Kto.-Nr. 200 733 (BLZ 503 308 00) ****************************************************************************