2
votes

The following happens, when I plot a histogram using matplotlib's hist function with horizontal orientation: Sometimes the bins with very low values, which are present at the default orientation, are not shown for the horizontal orientation.

Executing the following code in a notebook cell (sadly I cannot upload/should generate two histograms, where you can see the difference at most right/left bins of the distribution. For default there are small bins at ~3 and -3, which are not present for the horizontal orientation.

import numpy as np
import matplotlib.pyplot as plt
np.random.seed(20)
y = np.random.normal(size=1000000)
plt.hist(y, bins=20)
plt.show()
plt.hist(y, bins=20, orientation='horizontal')
plt.show()

I also linked the plots here:

default - horizontal

Does anybody have an idea what is the issue here?

1
What is your matplotlib version?BrenBarn
I can't reproduce your problem. The steps at 3, -3 are visible in both plots. matplotlib2.2 hereMr. T
The images look as if they are cropped. Could you make the code and the images consistent? What are the images that are produced by this code? (They should have axes and labels and stuff.)ImportanceOfBeingErnest

1 Answers

0
votes

I had similar issues with matplotlib's hist function. Sadly, I reverted to using barh and numpy.histogram() by hand.

Your code could then look like:

y = np.random.normal(size=1000000)
yhist = np.histogram(y, bins=20)
plt.barh(y=yhist[1][:20], x=yhist[0])
plt.show()