1

I am trying to make the numbers on my y axis not over lap with each other as shown in the image below. I have my code using matplotlib to plot all 8 plots at time using the plt.tight_layout() command. I am not sure what is the best way to fix the overlapping seen in the bottom four plots.

enter image description here

import matplotlib.pyplot as plt
fig = plt.figure()
a1 = fig.add_subplot(421)
a2 = fig.add_subplot(422)
a3 = fig.add_subplot(423)
a4 = fig.add_subplot(424)
a5 = fig.add_subplot(425)
a6 = fig.add_subplot(426)
a7 = fig.add_subplot(427)
a8 = fig.add_subplot(428)

a1.plot(Msol, ilP, color='blue')
a1.set_xlabel(r'$M/M\odot$')
a1.set_ylabel(r'$Log Pressure$')

a2.plot(Msol, ilT, color='blue')
a2.set_xlabel(r'$M/M\odot$')
a2.set_ylabel(r'$Log Temperature$')

a3.plot(Msol, ilRho, color='blue')
a3.set_xlabel(r'$M/M\odot$')
a3.set_ylabel(r'$Log Density$')

a4.plot(Msol, Rsol, color='blue')
a4.set_xlabel(r'$M/M\odot$')
a4.set_ylabel(r'$R/R\odot$')

a5.plot(Msol, Lsol, color='blue')
a5.set_xlabel(r'$M/M\odot$')
a5.set_ylabel(r'$L/L\odot$')

a6.plot(Msol, iK, color='blue')
a6.set_xlabel(r'$M/M\odot$')
a6.set_ylabel(r'$Opacity$')

a7.plot(Msol, ieg, color='blue')
a7.set_xlabel(r'$M/M\odot$')
a7.set_ylabel(r'$\epsilon$')

a8.plot(Msol, ir_c, color='blue')
a8.set_xlabel(r'$M/M\odot$')
a8.set_ylabel(r'$Convective Ratio$')

plt.tight_layout()
plt.show()
user1821176
  • 1,141
  • 2
  • 18
  • 29

2 Answers2

2

use get_ylim, set_yticks and possibly set_fontsize

import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot( np.random.randn( 1000 ).cumsum( ) )

lb, ub = ax.get_ylim( )
ax.set_yticks( np.linspace(lb, ub, 25 ) )

for x in ax.get_yticklabels( ):
    x.set_fontsize( 'small' )

tight

behzad.nouri
  • 74,723
  • 18
  • 126
  • 124
1

According to this page, tight_layout works only on position and padding of the graphs, and not on the ticks range and number. As you know that your graphs will be small, maybe you should adjust the number of ticks on your own?

Community
  • 1
  • 1
Joël
  • 2,723
  • 18
  • 36