Reputation: 1866
I am plotting a histogram using matplotlib, my code is bellow. In the second plot if i set the histtype='step' I loose three bins of the data and cannot work out why. Has anyone had this problem before? If I change the histtype='bar' the plot looks fine.See image attached.
Code 1:
plt.hist(DelB[Sp],bins=20,histtype='step',normed=True,label='Sp')
dd=np.concatenate((DelB[S0],DelB[E]))
plt.hist(dd,bins=15,color='g',histtype='step',normed=True,label='E+S0')
plt.xlim(0.4,2.3)
ylabel('normalized fraction',size=15)
plt.legend()
Code2:
plt.hist(DelB[Sp],bins=20,alpha=0.5,facecolor='blue',normed=True,label='Sp')
dd=np.concatenate((DelB[S0],DelB[E]))
plt.hist(dd,bins=15,alpha=0.5,facecolor='green',normed=True,label='E+S0')
plt.xlim(0.4,2.3)
plt.legend()
ylabel('normalized fraction',size=15)
Upvotes: 2
Views: 1537
Reputation: 1557
Your axis limits in the second plot are different. You can't see bars that are below the image boundary. Adding plt.ylim(0,2)
will solve the issue
Upvotes: 2