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. **************************************************************************** ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users