0

My code:

import matplotlib.pyplot as plt
import numpy as np

f = plt.figure()
production_level = [54, 83, 21, 3] #list_of_prod
periods = [x+1 for x in range(len(production_level))] #list_of_order

plt.bar(periods, production_level, color='orange')

plt.title('Dynamic lot-size problem chart')
plt.ylabel('Units')
plt.xlabel('Periods')
plt.grid(True)

plt.show()
f.savefig("bar.png", bbox_inches='tight')

Output: enter image description here

How can I have just whole numbers on x axis (1,2,3,4) without 0,5; 1,5; 2,5 etc.? How can add bars' value on them or above them?

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
Sanches3
  • 3
  • 1

1 Answers1

0

Add text by using plt.text() and tweaking the coordinates (hint, hardcoding these values might not be the best idea).

Change ticks by using plt.xticks() (see also this question).

andwerb
  • 153
  • 6