I am aware of some similar questions but I have tried the code on them and it does not work in my environment. So I have a large list of data (floating point numbers) and I want to plot it as a histogram. Although I can plot absolute frequency easily, I would like to plot relative frequency (fractions/percentages on the ordinate, i.e. y-axis). My code is:
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
#1 - n, bins, patches = ax.hist(zdata, bins=ceil(min-max), normed=1, cumulative=0)
#2 - n, bins, patches = ax.hist(zdata, weights=np.zeros_like(data) + 1. / data.size)
ax.set_xlabel('Atomic z coordinate', size=ceil(min-max))
ax.set_ylabel('Relative Frequency')
ax.legend
plt.show()
I have noticed that python asks for the bin count as an integer, but I know that I use 70 so that is easy to fix. My more urgent question is, when I try both commands that I have commented out in this snippet, neither works. Case 1 does not raise an error but when I finish the commands and call show() the figure does not appear. Case 2 raises a NameError and complains that it does not know what "data" is. I followed the template in other questions and am not sure myself what "data" is; my array (list) of values is zdata. Also, is there a difference between bins and patches?
I am using python 2.7.3 and the IDE is Spyder 2.1.11. Many thanks and I apologize if this is very similar to past questions.