Matplotlib x position
Now I am doing some graphs using python. When xtick is too long, the xtick is outside the graph. As shown below:
I know we can tweak it when we save the figure with plt.savefig ("plot_name", bbox_inches = 'tight'), but that will resize the numbers if I create multiple plots when I compile in latex as shown below.
I want all of my graphics to be the same size, and then when I compile to latex they will be the same size.
Can anyone suggest me some hint for a solution to this problem? Many thanks.
Code for these plots: (this posted code is not exactly the same code as above because I cannot post it. But these two are almost the same, the only difference is that one has for loop to make multiple digits , others list all the numbers.)
params = {'backend': 'ps',
'font.size': 30,
'font.style': 'normal',
'axes.labelsize': 30,
#'text.fontsize': 30,
'axes.linewidth': 2,
'legend.fontsize': 12,
'xtick.labelsize': 25,
'ytick.labelsize': 25,
'text.usetex': True,
'ps.usedistiller': 'xpdf'}
rcParams.update (PARAMS)
for i in range(len(sepa_step)):
if i == len(sepa_step) - 1:
continue
if i % 3 == 0: ########### calculating average flux
stack_flux1 = stack[i] / stack_num[i]
stack_flux2 = stack[i+1] / stack_num[i+1]
stack_flux3 = stack[i+2] / stack_num[i+2]
f, (ax1, ax2, ax3) = plt.subplots(3, sharex=True, sharey=False,figsize=(10,20))
ax1.plot(wave_alpha,stack_flux1,'-b',linewidth=4)
ax1.set_ylabel(r'$10^{-17} \ {\rm erg} \ {\rm cm}^{-2} \ {\rm s}^{-1} \ {\rm \AA}^{-1}$',fontsize = 30)
ax1.tick_params('both', length=10, width=2, which='major')
ax1.tick_params('both', length=5, width=2, which='minor')
ax1.axvline(x=6562.81, linewidth=4, color='r',linestyle='--')
ax2.plot(wave_alpha,stack_flux2,'-b',linewidth=4)
ax2.set_ylabel(r'$10^{-17} \ {\rm erg} \ {\rm cm}^{-2} \ {\rm s}^{-1} \ {\rm \AA}^{-1}$',fontsize = 30)
ax2.tick_params('both', length=10, width=2, which='major')
ax2.tick_params('both', length=5, width=2, which='minor')
ax2.axvline(x=6562.81, linewidth=4, color='r',linestyle='--')
ax3.plot(wave_alpha,stack_flux3,'-b',linewidth=4)
ax3.set_ylabel(r'$10^{-17} \ {\rm erg} \ {\rm cm}^{-2} \ {\rm s}^{-1} \ {\rm \AA}^{-1}$',fontsize = 30)
ax3.set_xlabel(r'$\lambda$ ($\AA$)',fontsize = 30)
ax3.tick_params('both', length=10, width=2, which='major')
ax3.tick_params('both', length=5, width=2, which='minor')
ax3.axvline(x=6562.81, linewidth=4, color='r',linestyle='--')
title1 = 'separation ' + str(sepa_step[i]) + '$\sim$' + str(sepa_step[i+1]) + ' mpc'
title2 = 'separation ' + str(sepa_step[i+1]) + '$\sim$' + str(sepa_step[i+2]) + ' mpc'
title3 = 'separation ' + str(sepa_step[i+2]) + '$\sim$' + str(sepa_step[i+3]) + ' mpc'
ax1.set_title(title1,fontsize=20)
ax2.set_title(title2,fontsize=20)
ax3.set_title(title3,fontsize=20)
#f.subplots_adjust(hspace=0.5)
plot_name = './plots_fiton/separation_' + str(i/3 + 1) + '.eps'
#plt.subplots_adjust(left=0.25, right=0.9, top=0.95, bottom=0.05)
plt.savefig(plot_name,bbox_inches='tight')
source to share
You can customize all the parameters of the graph in the matplotlibrc
file , including the size of the fields. Usually the file is located ~/.config/matplotlib/matplotlibrc
in Linux. The file is not created by default, so I suggest copying this template and then modifying it.
You may be interested in the following settings:
# The figure subplot parameters. All dimensions are a fraction of the
# figure width or height
figure.subplot.left : 0.125 # the left side of the subplots of the figure
figure.subplot.right : 0.9 # the right side of the subplots of the figure
figure.subplot.bottom : 0.1 # the bottom of the subplots of the figure
figure.subplot.top : 0.9 # the top of the subplots of the figure
figure.subplot.wspace : 0.2 # the amount of width reserved for blank space between subplots
figure.subplot.hspace : 0.2 # the amount of height reserved for white space between subplots
which determine how much space is left around the graph.
source to share