-1

I am trying to annotate a subplot. I would like to put a letter inside the plot so to help when I will write the caption..

so far I am trying in this way. no results. any help?

fname='SHOT_'+str(shot)
plt.figure(fname)
ftitle='Time Traces - '+str(nshot[i])
plt.suptitle(ftitle, fontsize=11)

#PLOT 1
ax1 = plt.subplot(711)
# xy = get_axis_limits(ax1)
# print(xy)


plt.scatter(timetraces['Time_LID3'], savitzky_golay(np.array(timetraces['KG1V/LID3']), 17, 1),color='red', label="KG1V",s=10)
fxlabel='Time [s]'
fylabel='$part/m^{-2}$'
plt.locator_params(axis='y',nbins=4)
# plt.xlabel(fxlabel,{'color': 'k','size': 11})
plt.ylabel(fylabel,{'color': 'k','size': 8})
plt.setp(ax1.get_xticklabels(), visible=False)
plt.legend(prop={'size':8})
ax1.yaxis.set_minor_locator(AutoMinorLocator())
ax1.xaxis.set_minor_locator(AutoMinorLocator())
ax1.annotate('G', xy=get_axis_limits(ax1))
plt.subplots_adjust(wspace=0, hspace=0)
plt.show()
bruvio
  • 853
  • 1
  • 9
  • 30

1 Answers1

2

I'm not 100% sure what you want to achieve, but I suspect something like below:

import matplotlib.pyplot as plt

ax1 = plt.subplot(121)
plt.text(0.05, 0.95, "A", fontweight="bold", transform=ax1.transAxes)
ax2 = plt.subplot(122)
plt.text(0.05, 0.95, "B", fontweight="bold", transform=ax2.transAxes)
plt.show()

Result: enter image description here

MPA
  • 1,878
  • 2
  • 26
  • 51
  • This way if the variable I’m plotting is outside [0,1] the metter will not show – bruvio May 02 '18 at 16:17
  • 1
    I've used the `transform` property to ensure that the annotation is always at 5% of the subplot width, and 95% of the subplot height, regardless of the absolute values on the axes. The annotation will always be in the top-left corner, no matter what – MPA May 02 '18 at 16:20