Hi, I am attempting to build a set of Figure objects (based on matplotlib.figure) which are essentially the same chart with different x-axis limits. I would like to do this in a function that returns the figures in a list so that i can choose to write some or all of the figures to a multipage PDF at a later date.
I attempted to do the following: ======================================================== import matplotlib.figure as fig from matplotlib.backends.backend_pdf import PdfPages, FigureCanvasPdf xdata = [1,2,3,4,5] ydata = [5,4,3,2,1] fig1 = fig.Figure(figsize=(2,2)) ax1 = fig.Figure.add_subplot(fig1,111) ax1.plot(xdata,ydata) figures = [] ax1.set_xlim([0,3]) figures.append(fig1) ax1.set_xlim([3,5]) figures.append(fig1) pdf = PdfPages('output.pdf') for figure in figures: canvas = FigureCanvasPdf(figure) figure.savefig(pdf, format="pdf") pdf.close() ======================================================== In the actual code the list of figures is returned from a function to another part of the code, but this is roughly equivalent. I realise in this example i can just write directly to the pdf file after appending fig1, but in the actual code i do not wish to write the data to a file until later on. 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? I have tried to use copy.copy() and copy.deepcopy(). The former does not work correctly (for fairly obvious reasons) and the latter does not work with the figure object giving me an error: "NotImplementedError: TransformNode instances can not be copied. Consider using frozen() instead." So, how can i go about making a list of 'charts' and then output them selectively to a PDF at a later time? Many thanks and apologies for any information I have left out. Stephen P.S. as an aside, can anyone confirm whether it is possible to write a multipage PDF using the cairo backend? ------------------------------------------------------------------------------ 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