0

The following line of code prints the standard deviation and mean on my graph using matplotlib in python. My question is. How do I convert the values to 2 decimals?

ax.text(60, 0.01, r'$\mu={},\ \sigma={}$'.format(np.mean(stat_input),np.std(stat_input)))
ShibbyBoss
  • 55
  • 1
  • 7

1 Answers1

1
>>> '{:.2f}'.format(123.456789)
'123.46'

For details see: Format String Syntax

So, in your case the line becomes:

ax.text(60, 0.01, r'$\mu={:.2f},\ \sigma={:.2f}$'.format(
    np.mean(stat_input), np.std(stat_input)
))
Igonato
  • 10,175
  • 3
  • 35
  • 64