I am trying to make a series of histograms by looping through a series of arrays containing values. For each array my script is producing a separate histogram. Using the default settings, this results in histograms in which the bar with the highest frequency touches the top of the graph (this is what it looks like now). I would like there to be some space: this is what I want it to look like.
My question is: how do I make the maximum value of the y-axis dependent of the maximum frequency occurring in my bins? I want the y-axis to be slightly longer than my longest bar.
I cannot do this by setting the value like so:
plt.axis([100, 350, 0, 5]) #[xmin, xmax, ymin, ymax]
or
matplotlib.pyplot.ylim(0,5)
because I am plotting a series of histograms, and the max frequencies strongly vary.
My code now looks something like this:
import matplotlib.pyplot as plt
for LIST in LISTS:
plt.figure()
plt.hist(LIST)
plt.title('Title')
plt.xlabel("x-axis [unit]")
plt.ylabel("Frequency")
plt.savefig('figures/'LIST.png')
How do I define the y-axis to run from 0 to 1.1 * (the max frequency in 1 bin)?