1

I have several arrays that contain measurement data of sensors. I would like to compare the frequency distribution of each array by plotting histograms with the help of matplotlib. My problem is, that the automatically scaled y-axis for each histogram differs, so that i can't compare them true to scale when i regard them side by side. On the following pictures in the links you can see, that the max value of the y axis is 18% on the green one and 30% on the gray one. In this case, I would like to have them automatically scaled by the highest percentage that occured: 30% green gray

Here is my code extract that I use to plot each of the histograms:

x = array_torque_VR
weights = 100*numpy.ones_like(x)/len(x) #maximum y-axis value is 100%
n, bins, patches = pyplot.hist(x, 20, weights=weights, facecolor='lime')
pyplot.xlabel('Torque in Nm')
pyplot.ylabel('Frequency in %')

I know, that it is possible to set a fixed max y-axis value by "pyplot.ylim()". But in my case it is important to get this value automatically scaled and i didn't find nothing to do so.

Do you think that there is a solution for this problem? Many thanks in advance for your help!

Compact
  • 11
  • 2

1 Answers1

0

You should separate the data creation for the histogram and the actual plotting. Use numpy.histogram to get the data, and then plot all your different cases at the same time. This works more effectively than using the pyplot.hist function a few times in a row.

See also the code I wrote here:

Probability Distribution Function Python

Community
  • 1
  • 1
Chiel
  • 6,006
  • 2
  • 32
  • 57