Reputation: 2106
Here is the reproducible issue. When plotting an indicator variable in this first example where there is density in both the 0 and 1 state everything looks fine. (I am going to cut off the x axis from 0 to 1, but left it this way for comparison with next part.)
plt.hist([np.append(np.zeros(1), np.ones(9)), np.ones(10)], normed=True)
plt.xlim([0,1.2])
plt.ylim([0,10])
However, if I plot this where all the density is in the 2nd state, all of the sudden the bars shift to the right of the 1.0 marker and disappear if I limit my axis
plt.hist([np.ones(10), np.ones(10)], normed=True)
plt.xlim([0,1.2])
plt.ylim([0,10])
Upvotes: 0
Views: 601
Reputation: 14847
The dynamically chosen bins are going to be different for different sets of data. Try adding something like bins=np.arange(0,1.1,.1)
to the plt.hist() calls and they should come out looking the same.
One of the things plt.hist returns is the list of bins it chose. In the first example, it gives [ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ]
, which is the equivalent of np.arange(0,1.1,.1). The second plot doesn't need to accommodate zeroes since the data don't contain any, and so plt.hist chooses [ 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2, 1.3, 1.4, 1.5]
.
Upvotes: 2