python - Matplotlib Stacked Histogram Bin Width -


when creating stacked histogram in matplotlib noticed bin widths shrink. in simple example:

import numpy np import matplotlib import matplotlib.pylab plt  #create histograms , plots fig = plt.figure() gs = matplotlib.gridspec.gridspec(1, 2) h1 = fig.add_subplot(gs[0]) h2 = fig.add_subplot(gs[1])  x = np.random.normal(0, 5, 500) y = np.random.normal(0, 20, 500)  bins = np.arange(-60,60, 5)  h1.hist([x, y], bins=bins, stacked=true) h2.hist(x, bins=bins, alpha=1) h2.hist(y, bins=bins, alpha=0.5)  plt.tight_layout() plt.show() filename = 'sample.pdf' plt.savefig(filename) 

i following output:

enter image description here

notice histogram on left has spacing between each bin though both left , right histograms using same bins.

is there way correct behavior? histogram on left use full bin widths such neighboring bins share edge.

if first argument of ax.hist-call list of lists (or 2d numpy-array or combination of two) automatically make bins smaller. rwidth parameter of ax.hist-call parameter determines bin-width. setting 1 want do:

h1.hist([x, y], bins=bins, stacked=true, rwidth=1)


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

python 3.5 - Pyqtgraph string in x tick -