I wish to create a histogram with no gaps between the bars. Tried to add argument bin
or range
but with no success.
import numpy as np
from matplotlib import pyplot as plt
population = 100
possible_answers = 4
scores = np.random.choice(range(possible_answers),population)
plt.hist(scores)
plt.show()
You need to use the bins
argument to adjust which bins are used.
import numpy as np
from matplotlib import pyplot as plt
population = 100
possible_answers = 4
scores = np.random.choice(range(possible_answers),population)
plt.hist(scores, bins=range(possible_answers+1), ec="k")
plt.show()
Or, if you want to shift the bins
plt.hist(scores, bins=np.arange(possible_answers+1)-0.5, ec="k")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.