diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index 668beec0dbe5..93e35a132be1 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -7920,7 +7920,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, _barfunc = self.barh else: # orientation == 'vertical' _barfunc = self.bar - + for m, c in zip(n, color): patch = _barfunc(bins[:-1]+boffset, m, width, bottom, align='center', log=log, @@ -7938,7 +7938,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, x[0::2], x[1::2] = bins, bins - minimum = min(bins) + minimum = np.min(n) if align == 'left' or align == 'center': x -= 0.5*(bins[1]-bins[0]) @@ -7946,7 +7946,29 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, x += 0.5*(bins[1]-bins[0]) if log: - y[0],y[-1] = minimum, minimum + #in the case of log scale there are three cases + #to consider for the y axis limit + #1) has zero or negative bin but other bins may be 00): + if np.all(ndata[ndata!=0]>=1): + minimum = 0.1 # case 2) + else: + minimum = np.min(ndata[ndata>0])*0.1 #case 1) + else: + minimum = 0.1 #case 3) + if orientation == 'horizontal': self.set_xscale('log') else: # orientation == 'vertical' @@ -7957,7 +7979,11 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, for m, c in zip(n, color): y[1:-1:2], y[2::2] = m, m if log: - y[y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log.pdf b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log.pdf new file mode 100644 index 000000000000..0dc3adf7c35e Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log.png b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log.png new file mode 100644 index 000000000000..c03ad9e39f2b Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log.svg b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log.svg new file mode 100644 index 000000000000..a1ece6dd6433 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log.svg @@ -0,0 +1,1098 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw.pdf b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw.pdf new file mode 100644 index 000000000000..8ee1c97aedd9 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw.png b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw.png new file mode 100644 index 000000000000..c55dda953d83 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw.svg b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw.svg new file mode 100644 index 000000000000..60544c8c2a47 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw.svg @@ -0,0 +1,776 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw_log.pdf b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw_log.pdf new file mode 100644 index 000000000000..64aa3fdc0959 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw_log.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw_log.png b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw_log.png new file mode 100644 index 000000000000..4018fc242c00 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw_log.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw_log.svg b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw_log.svg new file mode 100644 index 000000000000..6c21386894bc --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_nw_log.svg @@ -0,0 +1,1099 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b10b80464ff7..34e459d2f04d 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -672,6 +672,75 @@ def contour_dat(): z = np.cos(x) + np.sin(y[:, np.newaxis]) return x, y, z +@image_comparison(baseline_images=['hist_step']) +def test_hist_step(): + np.random.seed(0) + ndata = 10000 + d= np.random.randn(ndata)+500 + w= np.random.randn(ndata) + fig = plt.figure() + ax = fig.add_subplot(111) + ax.hist(d,bins=40,histtype='stepfilled') + + +@image_comparison(baseline_images=['hist_step_log']) +def test_hist_step_log(): + np.random.seed(0) + ndata = 10000 + d= np.random.randn(ndata)+500 + w= np.random.randn(ndata) + fig = plt.figure() + ax = fig.add_subplot(111) + ax.hist(d,bins=40,histtype='stepfilled',log=True) + + +@image_comparison(baseline_images=['hist_step_nw']) +def test_hist_step_nw(): + #test with negative weight + np.random.seed(0) + ndata = 10000 + d= np.random.randn(ndata)+500 + w= np.random.randn(ndata) + fig = plt.figure() + ax = fig.add_subplot(111) + ax.hist(d,bins=40,weights=w,histtype='stepfilled') + + +@image_comparison(baseline_images=['hist_step_nw_log']) +def test_hist_step_nw_log(): + #test with negative weight + np.random.seed(0) + ndata = 10000 + d= np.random.randn(ndata)+500 + w= np.random.randn(ndata) + fig = plt.figure() + ax = fig.add_subplot(111) + ax.hist(d,bins=40,weights=w,histtype='stepfilled',log=True) + + +@image_comparison(baseline_images=['hist2d']) +def test_hist2d(): + np.random.seed(0) + #make it not symetric in case we switch x and y axis + x=np.random.randn(100)*2+5 + y = np.random.randn(100)-2 + fig = plt.figure() + ax = fig.add_subplot(111) + ax.hist2d(x,y,bins=10) + + +@image_comparison(baseline_images=['hist2d_transpose']) +def test_hist2d_transpose(): + np.random.seed(0) + #make sure the the output from np.histogram is transposed before + #passing to pcolorfast + x=np.array([5]*100) + y = np.random.randn(100)-2 + fig = plt.figure() + ax = fig.add_subplot(111) + ax.hist2d(x,y,bins=10) + + @image_comparison(baseline_images=['contour_hatching']) def test_contour_hatching(): x, y, z = contour_dat()