I know that this question has been asked before here, but the answer given does not work for me.. When I put {} around my subscript, I am getting a Key Error. It happens whether I use "G${LA}$" or "G{LA}".
As an edit, this is a simplified version of the code I'm using:
X=np.array(random.sample(range(1000),10))
Y=np.array(random.sample(range(1000),10))
plt.clf()
f, ax =plt.subplots(1,1)
b, a = np.polyfit(X,Y, 1)
# 3.5 Calculate Pearson's correlation
r, SE = stats.pearsonr(X, Y)
r2 = r*r
# 3.6 Regression line to be added to plot - anchored text automatically locates the text, without the need to specifying the x,y coordinates
anchored_text = AnchoredText("GLA = {:3.2f}*GLD + {:3.2f}\n\nPearson's R = {:3.2f}, SE = {:3.2f}\n $R^2$ = {:3.2f}".format(b,a,r,SE,r2), loc=2)
# 3.7 Plot
ax = sns.regplot(X, Y, color='g')
ax.add_artist(anchored_text)
plt.show()
Now, if I add the subscript, it throws in the error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-31-00e10c71309f> in <module>()
19
20 # 3.6 Regression line to be added to plot - anchored text automatically locates the text, without the need to specifying the x,y coordinates
---> 21 anchored_text = AnchoredText(r"G$_{LA}$ = {:3.2f}*GLD + {:3.2f}\n\nPearson's R = {:3.2f}, SE = {:3.2f}\n $R^2$ = {:3.2f}".format(b,a,r,SE, r2), loc=2)
22
23 # 3.7 Plot
KeyError: 'LA'
Would that be because I am using AnchoredText? Or has anything changed since the other thread was posted?