Skip to content
Advertisement

Superscripting a string in python

Hello I am trying to superscript a string for a plot.

hallo= str(round(popt[1],1))
plt.plot(xFit, func(xFit,*popt),color='r', linestyle='--',label=f'Ideales DOE 125 u03bcJ <= 0,3 u03bcm F(x) = {round(popt[0],1)} * e$^{hallo}*x$ ')

And the result i get is:

enter image description here

The “-0,2*x” should be superscripted. What am I doing wrong? Thank you!

Advertisement

Answer

It IS making the - a superscript. To get the whole expression in there, you need to enclose the whole expression in curly braces. Since you have this in an f-string, where curly braces have meaning, that means you need these rather awkward triple-braces

plt.plot(xFit, func(xFit,*popt),color='r', linestyle='--',label=f'Ideales DOE 125 u03bcJ <= 0,3 u03bcm F(x) = {round(popt[0],1)} * e$^{{{hallo}}}*x$ ')
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement