python - Change Spyder and Matplotlib figure size for saved plots only -


i view matplotlib plots inside spyders ipython console in 1 size , save figures multipage pdf in different size.

currently set figure size follows:

plt.rc('axes', grid=true) plt.rc('figure', figsize=(12, 8)) plt.rc('legend', fancybox=true, framealpha=1) 

then plot figures , save them list saving pdf later on. works fine when used alone. plots approriately sized viewing in spyder ipython console.

at end of script have loop go through each of figures want save. in here want set layout , figure size better printing on a3 paper.

with pdfpages('multi.pdf') pdf:     fig in figs:         fig.tight_layout()         fig.set_size_inches(420/25.4, 297/25.4)         pdf.savefig(figure=fig) 

the output pdf want be, problem plots shown inside spyder. changing figure size while saving affects plots viewed inside spyder. , using size of a3 makes plots way big.

so question is: how change size of saved pdf figures without changing size of figures shown inside spyder?

as suggested @importanceofbeingernest, changing figure size after saving should work , may solved problem.

but, depending on specific problem, possible going face scaling issues since size of figures saved in pdf bigger size of displayed in ipython console. if scale great on pdf, possible going big in ipython shown in example below:

enter image description here

if don't need plot interactive in ipython, solution may generate figures pdf , display scaled bitmap version of them in ipython console shown in code below:

import matplotlib.pyplot plt matplotlib.backends.backend_pdf import pdfpages import numpy np ipython.display import image, display try:  # python 2     cstringio import stringio bytesio except importerror:  # python 3     io import bytesio  # generate matplotlib figures looks on a3 format :  fig, ax = plt.subplots() ax.plot(np.random.rand(150), np.random.rand(150), 'o', color='0.35', ms=25,         alpha=0.85)  ax.set_ylabel('ylabel', fontsize=46, labelpad=25) ax.set_xlabel('xlabel', fontsize=46, labelpad=25) ax.tick_params(axis='both', which='major', labelsize=30, pad=15,                direction='out', top=false, right=false, width=3, length=10) loc in ax.spines:     ax.spines[loc].set_linewidth(3)  # save figure pdf in a3 format:  w, h = 420/25.4, 297/25.4 pdfpages('multi.pdf') pdf:     fig.set_size_inches(w, h)     fig.tight_layout()     pdf.savefig(figure=fig)     plt.close(fig)  # display in ipython sclaled bitmap using buffer save png :  buf = bytesio() fig.savefig(buf, format='png', dpi=90) display(image(data=buf.getvalue(), format='png', width=450, height=450*h/w,               unconfined=true)) 

which shows in ipython console as: enter image description here


Comments