From e864d94a2fbfa89cb2ea25f75057f6d6d5528229 Mon Sep 17 00:00:00 2001 From: Umair Idris Date: Tue, 17 Feb 2015 18:10:57 -0500 Subject: [PATCH 1/7] Fix hexbin raising ValueError on empty dataset --- lib/matplotlib/axes/_axes.py | 9 +++------ lib/matplotlib/tests/test_axes.py | 3 +++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index a21893fc3a45..1a0099b834a6 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3846,10 +3846,9 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None, if extent is not None: xmin, xmax, ymin, ymax = extent else: - xmin = np.amin(x) - xmax = np.amax(x) - ymin = np.amin(y) - ymax = np.amax(y) + xmin, xmax = (np.amin(x), np.amax(x)) if x else (0, 1) + ymin, ymax = (np.amin(y), np.amax(y)) if y else (0, 1) + # to avoid issues with singular data, expand the min/max pairs xmin, xmax = mtrans.nonsingular(xmin, xmax, expander=0.1) ymin, ymax = mtrans.nonsingular(ymin, ymax, expander=0.1) @@ -5606,8 +5605,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, # basic input validation flat = np.ravel(x) - if len(flat) == 0: - raise ValueError("x must have at least one data point") # Massage 'x' for processing. # NOTE: Be sure any changes here is also done below to 'weights' diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index cb2ac8e8cd66..cc5608ae9d9d 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -482,6 +482,9 @@ def test_hexbin_extent(): ax.hexbin(x, y, extent=[.1, .3, .6, .7]) +def test_hexbin_empty(): + # From #3886: creating hexbin on empty dataset raises ValueError + ax.hexbin([], []) @cleanup def test_hexbin_pickable(): From 287a815f4ac96c93f2bf82b46257b1d4aaa5e21a Mon Sep 17 00:00:00 2001 From: Umair Idris Date: Tue, 17 Feb 2015 18:18:37 -0500 Subject: [PATCH 2/7] Fix hist raising ValueError on empty dataset --- lib/matplotlib/axes/_axes.py | 2 ++ lib/matplotlib/tests/test_axes.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 1a0099b834a6..3b92adf32314 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5605,6 +5605,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, # basic input validation flat = np.ravel(x) + if len(flat) == 0: + return [], [], cbook.silent_list('No Patches') # Massage 'x' for processing. # NOTE: Be sure any changes here is also done below to 'weights' diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index cc5608ae9d9d..8614d4f9f403 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1005,6 +1005,9 @@ def test_hist_log(): ax.hist(data, fill=False, log=True) +def test_hist_empty(): + ax.hist([]) + @image_comparison(baseline_images=['hist_steplog'], remove_text=True) def test_hist_steplog(): np.random.seed(0) From 6deba68600fb28b50b4ab65cb2cc9dce67110827 Mon Sep 17 00:00:00 2001 From: Umair Idris Date: Tue, 17 Feb 2015 18:23:10 -0500 Subject: [PATCH 3/7] Add explanation for test_hist_empty --- lib/matplotlib/tests/test_axes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 8614d4f9f403..4e49df55c280 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -483,7 +483,7 @@ def test_hexbin_extent(): ax.hexbin(x, y, extent=[.1, .3, .6, .7]) def test_hexbin_empty(): - # From #3886: creating hexbin on empty dataset raises ValueError + # From #3886: creating hexbin from empty dataset raises ValueError ax.hexbin([], []) @cleanup @@ -1006,6 +1006,7 @@ def test_hist_log(): def test_hist_empty(): + # From #3886: creating hist from empty dataset raises ValueError ax.hist([]) @image_comparison(baseline_images=['hist_steplog'], remove_text=True) From 74a42669bcb51d6560ea9736db78ef7ec07f0ae1 Mon Sep 17 00:00:00 2001 From: Umair Idris Date: Tue, 17 Feb 2015 19:53:14 -0500 Subject: [PATCH 4/7] Fix test_hist_empty and test_hexbin_empty test cases. Improve docstring for hist. Fix ambiguous truth value in hexbin. --- lib/matplotlib/axes/_axes.py | 6 +++--- lib/matplotlib/tests/test_axes.py | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 3b92adf32314..1d147e3bcb20 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3846,8 +3846,8 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None, if extent is not None: xmin, xmax, ymin, ymax = extent else: - xmin, xmax = (np.amin(x), np.amax(x)) if x else (0, 1) - ymin, ymax = (np.amin(y), np.amax(y)) if y else (0, 1) + xmin, xmax = (np.amin(x), np.amax(x)) if x.any() else (0, 1) + ymin, ymax = (np.amin(y), np.amax(y)) if y.any() else (0, 1) # to avoid issues with singular data, expand the min/max pairs xmin, xmax = mtrans.nonsingular(xmin, xmax, expander=0.1) @@ -5394,7 +5394,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, Compute and draw the histogram of *x*. The return value is a tuple (*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*, [*patches0*, *patches1*,...]) if the input contains multiple - data. + data or ([], [], []) if input is an empty array. Multiple data can be provided via *x* as a list of datasets of potentially different length ([*x0*, *x1*, ...]), or as diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 4e49df55c280..8ffee18ed431 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -482,8 +482,10 @@ def test_hexbin_extent(): ax.hexbin(x, y, extent=[.1, .3, .6, .7]) +@cleanup def test_hexbin_empty(): # From #3886: creating hexbin from empty dataset raises ValueError + ax = plt.gca() ax.hexbin([], []) @cleanup @@ -1004,9 +1006,10 @@ def test_hist_log(): ax = fig.add_subplot(111) ax.hist(data, fill=False, log=True) - +@cleanup def test_hist_empty(): # From #3886: creating hist from empty dataset raises ValueError + ax = plt.gca() ax.hist([]) @image_comparison(baseline_images=['hist_steplog'], remove_text=True) @@ -3515,7 +3518,7 @@ def test_color_None(): def test_numerical_hist_label(): fig, ax = plt.subplots() ax.hist([range(15)] * 5, label=range(5)) - + @cleanup def test_move_offsetlabel(): data = np.random.random(10) * 1e-22 From a567658a790cb5b9d5e310b9bcc766ecaf98ed37 Mon Sep 17 00:00:00 2001 From: Umair Idris Date: Wed, 18 Feb 2015 18:43:48 -0500 Subject: [PATCH 5/7] Fix hist to return correct patches on empty input. Add test for hist step on empty input. --- lib/matplotlib/axes/_axes.py | 27 ++++++++++++++++++--------- lib/matplotlib/tests/test_axes.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 1d147e3bcb20..24c6f481f934 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5394,7 +5394,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, Compute and draw the histogram of *x*. The return value is a tuple (*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*, [*patches0*, *patches1*,...]) if the input contains multiple - data or ([], [], []) if input is an empty array. + data. Multiple data can be provided via *x* as a list of datasets of potentially different length ([*x0*, *x1*, ...]), or as @@ -5605,12 +5605,14 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, # basic input validation flat = np.ravel(x) - if len(flat) == 0: - return [], [], cbook.silent_list('No Patches') + + input_empty = len(flat) == 0 # Massage 'x' for processing. # NOTE: Be sure any changes here is also done below to 'weights' - if isinstance(x, np.ndarray) or not iterable(x[0]): + if input_empty: + x = np.asarray([[]]) + elif isinstance(x, np.ndarray) or not iterable(x[0]): # TODO: support masked arrays; x = np.asarray(x) if x.ndim == 2: @@ -5677,7 +5679,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, #hist_kwargs = dict(range=range, normed=bool(normed)) # We will handle the normed kwarg within mpl until we # get to the point of requiring numpy >= 1.5. - hist_kwargs = dict(range=bin_range) + hist_kwargs = dict(range=bin_range) if not input_empty else dict() n = [] mlast = None @@ -5760,6 +5762,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, for m, c in zip(n, color): if bottom is None: bottom = np.zeros(len(m), np.float) + if input_empty: + width = 0 if stacked: height = m - bottom else: @@ -5842,6 +5846,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, xvals.append(x.copy()) yvals.append(y.copy()) + fill_kwargs = dict() if not input_empty else dict(linewidth=0) + if fill: # add patches in reverse order so that when stacking, # items lower in the stack are plottted on top of @@ -5850,14 +5856,16 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, patches.append(self.fill( x, y, closed=True, - facecolor=c)) + facecolor=c, + **fill_kwargs)) else: for x, y, c in reversed(list(zip(xvals, yvals, color))): split = 2 * len(bins) patches.append(self.fill( x[:split], y[:split], closed=False, edgecolor=c, - fill=False)) + fill=False, + **fill_kwargs)) # we return patches, so put it back in the expected order patches.reverse() @@ -5870,17 +5878,18 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, if np.sum(m) > 0: # make sure there are counts xmin = np.amin(m[m != 0]) # filter out the 0 height bins - xmin = max(xmin*0.9, minimum) + xmin = max(xmin*0.9, minimum) if not input_empty else minimum xmin = min(xmin0, xmin) self.dataLim.intervalx = (xmin, xmax) elif orientation == 'vertical': ymin0 = max(_saved_bounds[1]*0.9, minimum) ymax = self.dataLim.intervaly[1] + for m in n: if np.sum(m) > 0: # make sure there are counts ymin = np.amin(m[m != 0]) # filter out the 0 height bins - ymin = max(ymin*0.9, minimum) + ymin = max(ymin*0.9, minimum) if not input_empty else minimum ymin = min(ymin0, ymin) self.dataLim.intervaly = (ymin, ymax) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 8ffee18ed431..e77e011bf3b4 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1007,10 +1007,37 @@ def test_hist_log(): ax.hist(data, fill=False, log=True) @cleanup -def test_hist_empty(): +def test_hist_bar_empty(): # From #3886: creating hist from empty dataset raises ValueError ax = plt.gca() - ax.hist([]) + + n, bins, patches = ax.hist([], histtype='bar') + + # empty hist should match empty numpy histogram + n1, bins1 = np.histogram([]) + assert_array_equal(n, n1) + assert_array_equal(bins, bins1) + + # check zero size patches + assert_true(len(patches) == 10) + for patch in patches: + assert_false(patch._height) + assert_false(patch._width) + +@cleanup +def test_hist_step_empty(): + # From #3886: creating hist from empty dataset raises ValueError + ax = plt.gca() + + n, bins, patches = ax.hist([], histtype='step') + + # empty hist should match empty numpy histogram + n1, bins1 = np.histogram([]) + assert_array_equal(n, n1) + assert_array_equal(bins, bins1) + + # check zero size patches + assert_true(len(patches) == 1 and not patches[0]._linewidth) @image_comparison(baseline_images=['hist_steplog'], remove_text=True) def test_hist_steplog(): From 2bf9777d5b53e4897d4b3269e0315be28454e3af Mon Sep 17 00:00:00 2001 From: Umair Idris Date: Fri, 13 Mar 2015 20:32:20 -0400 Subject: [PATCH 6/7] Fix width and weights for hist on empty input. Update tests for empty hist and hexbin to use baseline images. --- lib/matplotlib/axes/_axes.py | 16 ++++----- .../test_axes/hexbin_empty.png | Bin 0 -> 3744 bytes .../test_axes/hist_bar_empty.png | Bin 0 -> 4031 bytes .../test_axes/hist_step_empty.png | Bin 0 -> 3937 bytes lib/matplotlib/tests/test_axes.py | 34 +++++------------- 5 files changed, 14 insertions(+), 36 deletions(-) create mode 100644 lib/matplotlib/tests/baseline_images/test_axes/hexbin_empty.png create mode 100644 lib/matplotlib/tests/baseline_images/test_axes/hist_bar_empty.png create mode 100644 lib/matplotlib/tests/baseline_images/test_axes/hist_step_empty.png diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 24c6f481f934..003570f2c37f 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5611,7 +5611,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, # Massage 'x' for processing. # NOTE: Be sure any changes here is also done below to 'weights' if input_empty: - x = np.asarray([[]]) + x = np.array([[]]) elif isinstance(x, np.ndarray) or not iterable(x[0]): # TODO: support masked arrays; x = np.asarray(x) @@ -5641,7 +5641,9 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, # We need to do to 'weights' what was done to 'x' if weights is not None: - if isinstance(weights, np.ndarray) or not iterable(weights[0]): + if input_empty: + w = np.array([]) + elif isinstance(weights, np.ndarray) or not iterable(weights[0]): w = np.array(weights) if w.ndim == 2: w = w.T @@ -5762,8 +5764,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, for m, c in zip(n, color): if bottom is None: bottom = np.zeros(len(m), np.float) - if input_empty: - width = 0 if stacked: height = m - bottom else: @@ -5846,8 +5846,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, xvals.append(x.copy()) yvals.append(y.copy()) - fill_kwargs = dict() if not input_empty else dict(linewidth=0) - if fill: # add patches in reverse order so that when stacking, # items lower in the stack are plottted on top of @@ -5856,16 +5854,14 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, patches.append(self.fill( x, y, closed=True, - facecolor=c, - **fill_kwargs)) + facecolor=c)) else: for x, y, c in reversed(list(zip(xvals, yvals, color))): split = 2 * len(bins) patches.append(self.fill( x[:split], y[:split], closed=False, edgecolor=c, - fill=False, - **fill_kwargs)) + fill=False)) # we return patches, so put it back in the expected order patches.reverse() diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hexbin_empty.png b/lib/matplotlib/tests/baseline_images/test_axes/hexbin_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..28d79048f56a0cdd436f0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rp?!Uk`5n{L?1$Z2#kvPm6Y*kvr(V{BouYUwdJBx%s!>f8SU# zFxWh*ef#<+3-@TY9h5~@v1v8Kd~3P>zcRl+xcT|{>56|fGq-RsBvjwqAAkJ! z_t(wo_5UhCk*?^l&vF0XZ&h!;|GsI=z+jg5^Zow)bN!YVTF5**^V9JM?`T0hI4hyi zB70aj6Gw~eq23S_Ui;drno05dJuwh!(^q#$P^#as?daa^VD#`bCt3#w+@Ama`?ujS ziTwNf=I&`Z^|M9}*wp&QqXcat@0Fc@@3P(A?H}LU?u^l!epC6!i|g_AvgYRIo6{K> zKJee$Q)wKxx5~8oSh;6Ijk8_N4}-k?{NrE0ey#ZR Date: Wed, 18 Mar 2015 23:17:23 -0400 Subject: [PATCH 7/7] Fix hexbin to use len instead of any. Fix hist to pass in bin_range and not overwrite weights on empty input. --- lib/matplotlib/axes/_axes.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 003570f2c37f..56c7cd339d5f 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3846,8 +3846,8 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None, if extent is not None: xmin, xmax, ymin, ymax = extent else: - xmin, xmax = (np.amin(x), np.amax(x)) if x.any() else (0, 1) - ymin, ymax = (np.amin(y), np.amax(y)) if y.any() else (0, 1) + xmin, xmax = (np.amin(x), np.amax(x)) if len(x) else (0, 1) + ymin, ymax = (np.amin(y), np.amax(y)) if len(y) else (0, 1) # to avoid issues with singular data, expand the min/max pairs xmin, xmax = mtrans.nonsingular(xmin, xmax, expander=0.1) @@ -5641,9 +5641,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, # We need to do to 'weights' what was done to 'x' if weights is not None: - if input_empty: - w = np.array([]) - elif isinstance(weights, np.ndarray) or not iterable(weights[0]): + if isinstance(weights, np.ndarray) or not iterable(weights[0]): w = np.array(weights) if w.ndim == 2: w = w.T @@ -5669,7 +5667,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, # If bins are not specified either explicitly or via range, # we need to figure out the range required for all datasets, # and supply that to np.histogram. - if not binsgiven: + if not binsgiven and not input_empty: xmin = np.inf xmax = -np.inf for xi in x: @@ -5681,7 +5679,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, #hist_kwargs = dict(range=range, normed=bool(normed)) # We will handle the normed kwarg within mpl until we # get to the point of requiring numpy >= 1.5. - hist_kwargs = dict(range=bin_range) if not input_empty else dict() + hist_kwargs = dict(range=bin_range) n = [] mlast = None