Reputation: 1467
I would like to save to a different resolution all the plots generated in an ipython notebook. I know that I could add this line to each cell that shows a plot
plt.savefig('figure_1.pdf', dpi=300)
but that would require to add it manually when needed.
Is there any (reasonably) simple way to tell ipython to save each plot? Maybe by using a filename template like figure_X.pdf, where X is the cell's number?
Thanks
Upvotes: 3
Views: 2090
Reputation: 2477
Yes, just dynamically create a variable that is your desired output name.
outPDF = 'figure_{}.pdf'.format(cellNumber)
plt.savefig(outPDF, dpi=300)
So for example, if cellNumber = 5
, outPDF = 'figure_5.pdf'
Upvotes: 3