2
$\begingroup$

Also, the histogram bar widths are different on certain values of bin. How to keep the bar widths uniform? I have tried using the rwidth but that dos not solve my problem.

Data:

test    age
17 - Alpha OH PROGESTERONE - HORMONE ASSAYS 23
17 - Alpha OH PROGESTERONE - HORMONE ASSAYS 26
17 ALPHA HYDROXY PROGESTERONE   18
17 ALPHA HYDROXY PROGESTERONE   21
17 ALPHA HYDROXY PROGESTERONE   25
17 ALPHA HYDROXY PROGESTERONE   27

Code

axes = plt.gca()
axes.set_xlim(0, 100)
axes.set_ylim(0, 100)
plt.hist(df.loc[0:1,'age':'age'].to_numpy(),100, rwidth=0.9)

axes = plt.gca()
axes.set_xlim(0, 100)
axes.set_ylim(0, 100)
plt.hist(df.loc[2:5,'age':'age'].to_numpy(),10, rwidth=0.9)

axes = plt.gca()
axes.set_xlim(0, 100)
axes.set_ylim(0, 100)
plt.hist(df.loc[6:14,'age':'age'].to_numpy(),100, rwidth=0.9)

As you can see, in the first image, the bars are vanished on keeping the bins = 100

I can see the bars now on keeping the bins = 5

If you look carefully, in the third mage, which corresponds to the third histogram, the bars are of different widths (2 and 3 pixels wide in my screen)

$\endgroup$
2
  • $\begingroup$ could you provide us with some pictures of your plot, just to illustrate? $\endgroup$ Apr 11, 2019 at 3:26
  • $\begingroup$ I have updated the question. $\endgroup$ Apr 11, 2019 at 6:15

1 Answer 1

1
$\begingroup$

The height of a bar shows the number of measurements within that range.

The bars get shorter when you increase the bin count, because the more bins you have in total, the less measurements fall into an individual bin.

$\endgroup$
3
  • $\begingroup$ That is true. But then why do the bars also altogether vanish? Is it because the bins are so high that the height of bars is now in decimals? $\endgroup$ Apr 11, 2019 at 8:00
  • $\begingroup$ if you dont use normalized histograms (with frequency on the y-axis), then the y-axis represents the bin count, which is int. Therefore those low values are probably 0. $\endgroup$
    – pcko1
    Apr 11, 2019 at 8:26
  • $\begingroup$ by normalized I mean setting density=True in plt.hist() $\endgroup$
    – pcko1
    Apr 11, 2019 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.