GCien
GCien

Reputation: 2349

Placing of text by specifying distance from axes

I was wondering, when using the ax.text command on two different plots but a plot with which I would like to be the same figure in my paper, e.g.:

axScatter_Scatter.text(38.20, 2.76, r'$\mathrm{(a)}$', fontsize=12)
axScatter_Hist.text(2.8, 284.5, r'$\mathrm{(b)}$', fontsize=12)

Is it possible, rather than specifying rough xy co-ordinates, to specify a standard distance from the axes? So that both the (a) and (b) label positions are exact?

Any thoughts on this would be much appreciated, as I can't seem to find anything in the literature or through other means.

Upvotes: 0

Views: 64

Answers (2)

hitzg
hitzg

Reputation: 12701

As the documentation of text explains you can use the transform argument:

axScatter_Scatter.text(0.1, 0.1, r'$\mathrm{(a)}$', fontsize=12, 
        transform=axScatter_Scatter.transAxes)
axScatter_Hist.text(0.1, 0.1, r'$\mathrm{(b)}$', fontsize=12, 
        transform=axScatter_Hist.transAxes)

Now the coordinates for the text objects are interpreted as fractions of the axes.

Upvotes: 1

GCien
GCien

Reputation: 2349

Specific to my code, the above answer by @hitzg worked perfectly but for the following change:

axScatter_Scatter.text(0.05, 0.93, r'$\mathrm{(a)}$', fontsize=12, 
        transform=axScatter_Scatter.transAxes)
axScatter_Hist.text(0.05, 0.93, r'$\mathrm{(b)}$', fontsize=12, 
        transform=axScatter_Hist.transAxes)

The transform=ax.transAxes was changed to transform=axScatter_Hist.transAxes to be consistent with axScatter_Scatter = fig.add_subplot(121). Which is just my own personal labelling.

Upvotes: 1

Related Questions