numpy - Python histograms: Manually normalising counts and re-plotting as histogram -


i tried searching similar, , closest thing find this helped me extract , manipulate data, can't figure out how re-plot histogram. have array of voltages, , have first plotted histogram of occurrences of voltages. want instead make histogram of events per hour ( y-axis of normal histogram divided number of hours took data ) , re-plot histogram manipulated y data.

i have array contains number of events per hour ( composed of original y axis pyplot.hist divided number of hours data taken ), , bins histogram. have composed array using following code ( taken answer linked above ):

import numpy import matplotlib.pyplot pyplot mydata = numpy.random.normal(-15, 1, 500)      # seems have 'uneven' on either side of 0, otherwise code looks fine. fyi, actual data positive pyplot.figure(1) hist1 = pyplot.hist(mydata, bins=50, alpha=0.5, label='set 1', color='red') hist1_flux = [hist1[0]/5.0, 0.5*(hist1[1][1:]+hist1[1][:-1])] pyplot.figure(2) pyplot.bar(hist1_flux[1], hist1_flux[0]) 

this code doesn't match what's going on in code; data composed of 1000 arrays of 1000 data points each ( voltages ). have made histograms of that, gives me number of occurrences of given voltage range ( or bin width ). want re-plot histogram of number of events per hour (so yaxis of histogram / 5 hours) same original bin width, when divide hist1[0]/5 , replot in above way, 'bin width' wrong.

i feel there must easier way this, rather manually replotting own histograms.

thanks in advance, , i'm sorry if i've missed obvious.

the problem, illustrated in output of sample code , original data follows:

upper plots: code snippet output.
lower plots: actual data. upper plots: code snippet output. lower plots: actual data.

it's because bar function takes argument width, default 0.8 (plt.bar(left, height, width=0.8, bottom=none, hold=none, **kwargs)), need change distance between 2 bars:

pyplot.bar(hist1_flux[1], hist1_flux[0],            width=hist1_flux[1][1] - hist1_flux[1][0]) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -