Hi,I plotted some data in my figure canvas and now I want to save the figure
to pdf and in A4 size PDF. So I did the following:
   def handlePdfButton(self):   from matplotlib.backends.backend_pdf import
PdfPages        fileName = "sample.pdf" pdf = PdfPages(fileName)
self.fig.set_size_inches(8.267,11.692) # to make it A4 sizes
pdf.savefig(self.fig)   pdf.close()
Because I do self.fig.set_size_inches(8.267,11.692)  the application window
figure is also resized, I do not want this to happen. I need only A4 size
pdf, so how do I resize the application figure? Or please suggest if there
is any other way to save pdf in A4 size.I do not want the figure to be
resized after saving to PDF.Please share your views. Thanks for your help in
advance.Sample application code to test:
import sysimport numpy as npfrom matplotlib.figure import Figureimport
matplotlibmatplotlib.use("Qt4Agg")matplotlib.rcParams['backend.qt4']='PySide'from
matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas,
NavigationToolbar2QTAgg as NavigationToolbarfrom matplotlib.figure import
Figureimport PySidefrom PySide import QtGui, QtCoreclass
MyApp(QtGui.QMainWindow):    def __init__(self, parent=None):       
QtGui.QMainWindow.__init__(self, parent)        self.widget =
QtGui.QWidget()        self.fig = Figure((5.0, 4.0), dpi=100)       
self.canvas = FigureCanvas(self.fig)        self.toolbar =
NavigationToolbar(self.canvas, self)        self.PdfButton =
QtGui.QPushButton("PDF")       
self.PdfButton.clicked.connect(self.handlePdfButton)        vbox =
QtGui.QVBoxLayout()        vbox.addWidget(self.canvas)  # the matplotlib
canvas        vbox.addWidget(self.toolbar)      vbox.addWidget(self.PdfButton)  
     
self.widget.setLayout(vbox)        self.setCentralWidget(self.widget)       
self.axes = self.fig.add_subplot(111)        X = np.linspace(-np.pi, np.pi,
256, endpoint=True)        C, S = np.cos(X), np.sin(X)  self.axes.plot(X, C, 
linewidth=1.0, linestyle="-", label="cosine")   self.axes.plot(X, S, 
linewidth=1.0, linestyle="-", label="sine")        self.axes.legend()       
self.canvas.draw()        def handlePdfButton(self):    from
matplotlib.backends.backend_pdf import PdfPages fileName = "sample.pdf" pdf
= PdfPages(fileName)    self.fig.set_size_inches(8.267,11.692)
pdf.savefig(self.fig)        #self.fig.set_size_inches(8.267,11.692)
#self.fig.canvas.resize(20,20)  pdf.close()     #self.canvas.draw()def main():  
 
app = QtGui.QApplication(sys.argv)    form = MyApp()    form.show()   
app.exec_()if __name__ == "__main__":    main()




--
View this message in context: 
http://matplotlib.1069221.n5.nabble.com/Resize-the-fig-canvas-after-pdf-savefig-tp43358.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
• 3 signs your SCM is hindering your productivity
• Requirements for releasing software faster
• Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to