2

I am trying to plot some data using Matplotlib. My code works fine but there is a clash between my figure title and the top value of the y-axis ticks. So my question is, would anybody know how to remove the top value only from the y-axis whilst keeping everything else about the plot the same?

My code

cyp_minus=pandas.read_csv(cyp_minus_file,sep='\t')
cyp_plus=pandas.read_csv(cyp_plus_file,sep='\t')
plt.figure(9)
plt.plot(cyp_minus['Dose']*1000,cyp_minus['atRA_minus_tet'],label='Control')
plt.plot(cyp_plus['Dose']*1000,cyp_plus['Cyp26(atRA_plus_tet)'],label='RARa Overexpression')
x=plt.xlabel('[atRA] (nM)',fontsize=15)
plt.ylabel('[Cyp26A1]/beta-actin',fontsize=15)
plt.title('Effect of RARa overexpression on Cyp26A1 dose-response curve',fontsize=15)
plt.legend(loc=2,fontsize=15)
plt.rc('xtick', labelsize=20)
plt.rc('ytick', labelsize=20)
plt.savefig('Cyp26A1 DR-curve for presentation.tiff',dpi=500,bbox_extra_artists=[x], bbox_inches='tight')

Thanks

CiaranWelsh
  • 7,014
  • 10
  • 53
  • 106

2 Answers2

3

You can make your title go up so it doesn't overlap with the y top value:

plt.title('Effect of RARa overexpression on Cyp26A1 dose-response curve',fontsize=15, y=1.5) # Change y value accordinly
YOBA
  • 2,759
  • 1
  • 14
  • 29
3

As an alternative to the accepted answer, if you really do want to remove the text from a tick label, you can do so like this:

yticks = plt.gca().get_yticks().tolist() # get list of ticks
yticks[-1] = ''                          # set last tick to empty string
ax.set_yticklabels(yticks)               # set the labels
tmdavison
  • 64,360
  • 12
  • 187
  • 165