title: Combining a format string with a superscript and a subscript in pyplot when rendering text in a plot
body: <p>I would like to include the equation for a "power-law" curve I am creating using pyplot.  I have tried several variations of the following code:</p>
  
  <pre><code>ax.text(0.1,0.9,r'{0:}x$^{1:}$'.format(A,b))
  </code></pre>
  
  <p>of course the text renderer uses the curly brackets as well as the format statement.  I have tried doubling the curly brackets to have</p>
  
  <pre><code>ax.text(0.1,0.9,r'{0:}x$^{{1:}}$'.format(A,b))
  </code></pre>
  
  <p>and even tripling them</p>
  
  <pre><code>ax.text(0.1,0.9,r'{0:}x$^{{{1:}}}$'.format(A,b))
  </code></pre>
  
  <p>I have also tried splitting the text into two lines</p>
  
  <pre><code>exponent = '{0:}$'.format(b)
  ax.text(0.1,0.9,r'{0:}x$^'.format(A)+exponent)
  </code></pre>
  
  <p>none of these really make sense to me or to pyplot, but I can't seem to ask the right search question to get this to work.  I have found answers that suggested splitting the line and using double curly brackets but nothing that will make this work.  Is this possible?</p>
  
  <p>EDIT:</p>
  
  <p>Through further experimentation I have answered the question above which was a simplified version of the equation I wanted to put in the plot, so let me change this question slightly.  To do what I wanted above I have found that:</p>
  
  <pre><code>ax.text(0.1,0.9,r'{0:}x$^{{ {1:} }}$'.format(A,b))
  </code></pre>
  
  <p>works.  I don't know why I hadn't tried it earlier, but I have now.  The problem is that I actually want a subscript on x as well.  Given that the above works I would have thought that:</p>
  
  <pre><code>ax.text(0.1,0.9,r'{0:}x$^{{ {1:} }}_{{\rm map}}$ 
  </code></pre>
  
  <p>would work, but I get the following error:</p>
  
  <blockquote>
    <p>Subscript/superscript sequence is too long.  Use braces { } to remove
    ambiguity. (at char 0), (line:1, col:1)</p>
  </blockquote>
  
  <p>I cannot see where to add braces that will remove any ambiguity.  Can anyone tell me what I need to do?</p>