Home > Net >  Pyplot - format label in math mode of a variable
Pyplot - format label in math mode of a variable

Time:11-05

g = 0.0
for i in range(0,5,1):
    plt.plot(a,b,label='$K_{0:.2f}(x)$'.format(g))
    g  = 0.31

I do not manage to get the whole number in subscript in math mode, it displays just the first in subscript.

How can this issue be solved?

CodePudding user response:

This should work fine:

plt.plot(a,b,label='$K_{%s}(x)$' % "{0:.2f}".format(g))
  • Related