s kemp <6b656...@gmail.com> writes: > The output i get from this code is two identical pages of PDF where > the x limits are set to 3,5. I understand this is because I am simply > making two identical references to the figure object in the list and > by modifying fig1 i also affect the fig1 that is 'stored' in the first > position of the array. My question is how do I avoid this?
My recommendation is to construct multiple figure objects. Factor the shared code into a function so it is easier to modify just what you want to be different between the figures: ------------------------------------------------------------------------ import matplotlib.figure as fig from matplotlib.backends.backend_pdf import PdfPages, FigureCanvasPdf def plot_data(xdata, ydata): """Returns pair of figure and axis""" f = fig.Figure(figsize=(2,2)) ax = f.add_subplot(111) ax.plot(xdata, ydata) return f, ax xdata = [1,2,3,4,5] ydata = [5,4,3,2,1] fig1, ax1 = plot_data(xdata, ydata) fig2, ax2 = plot_data(xdata, ydata) figures = [] ax1.set_xlim([0,3]) figures.append(fig1) ax2.set_xlim([3,5]) figures.append(fig2) pdf = PdfPages('output.pdf') for figure in figures: canvas = FigureCanvasPdf(figure) figure.savefig(pdf, format="pdf") pdf.close() ------------------------------------------------------------------------ -- Jouni K. Seppänen http://www.iki.fi/jks ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2dcopy2 _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users