Reputation: 473
I'm trying to print a result in pyplot using plt.legend, but the superscript
${0}^{1}
prints my {1} float (and even string) as the first part of that float(or string)
tit='The resonance position is ${0}^{1}$'.format(xl[0],xp,xm)
the result on the image(since I can't post a screenshot, I'll type it out:
+
The resonance position is 8.71 0.19
or if I get rid of the '+'
0
The resonance position is 8.71 .19
whilst {1}, i.e. xp (a string) is
'+0.19'
What am I doing wrong?
This is my first time using StackOverflow, I searched for this specific question and problem and couldn't find anything. So if this question had already been answered - I'm sorry!
Thank you
Upvotes: 2
Views: 1132
Reputation: 4058
Use integer/float values no strings. You can use %d
, %f
and %s
etc.
Just stay at the natural datatype. Conversion to string is not necessary. Using format
is slower than just use string formatting with %
"${%+.2f}^{%+.2f}$" % (float("8.71"), float("+0.19"))
You could kinf of "debug" it if you just print the string. You have to look that there have to be parentesis.
Upvotes: 0
Reputation: 15909
In latex it would be as $8.5^{9.67}$, if not it will only upper the first digit, as you report. So you will need to change:
${0}^{1}$
To:
${0}^{{1}}$
(Or ${0}^{{1}}$ not sure.)
Before formating it.
Upvotes: 2