1

I am rather new to Python 2.7 and Pandas. I have a bar graph and would like to add annotations like mean, variance, etc. I already computed above in the graph. My current graph looks like this:

enter image description here

Along with this line of code:

matplotlib.pyplot.title('All the observation', fontsize=16)
matplotlib.pyplot.annotate( mean, ( 0 , 0), ( 0, 14000), fontsize=16)
matplotlib.pyplot.show()

Does someone have any idea on how to add on the graph the mean etc in a proper and nice way?

Thank you in advance for your help!

Best, Viktor

Mr. T
  • 11,960
  • 10
  • 32
  • 54
viktor.w
  • 33
  • 1
  • 5

1 Answers1

1

You could use this:

matplotlib.pyplot.figtext(.6, .8, "Mean = {}".format(mean))

If you have more values to add:

plt.figtext(.6, .8, "Mean = {}\nVariance = {}".format(mean, variance))

enter image description here

Ps. usually matplotlib.pyplot is imported in this way:

import matplotlib.pyplot as plt
Joe
  • 12,057
  • 5
  • 39
  • 55
  • I would also suggest using some string formatting: `"Mean = {:.3f}".format(mean)` to make the digit display a little easier to handle. I also wouldn't use boxplots, generally, there's a ton of good reasons not to. – Andrew Nov 27 '18 at 09:34
  • Yes thanks it works perfectly! thank you! – viktor.w Nov 27 '18 at 09:35