From 75ef70b2569d44e4e3c06dd00a8d2866151ca092 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 17 Nov 2016 13:42:26 -0800 Subject: [PATCH] Minor cleanup of hist(). --- lib/matplotlib/axes/_axes.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index c4f05f85df94..205d6d3d3b95 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6273,7 +6273,7 @@ def _normalize_input(inp, ename='input'): totwidth = np.diff(bins) if rwidth is not None: - dr = min(1.0, max(0.0, rwidth)) + dr = np.clip(rwidth, 0, 1) elif (len(n) > 1 and ((not stacked) or rcParams['_internal.classic_mode'])): dr = 0.8 @@ -6281,20 +6281,15 @@ def _normalize_input(inp, ename='input'): dr = 1.0 if histtype == 'bar' and not stacked: - width = dr*totwidth/nx + width = dr * totwidth / nx dw = width - - if nx > 1: - boffset = -0.5*dr*totwidth*(1.0-1.0/nx) - else: - boffset = 0.0 - stacked = False + boffset = -0.5 * dr * totwidth * (1 - 1 / nx) elif histtype == 'barstacked' or stacked: - width = dr*totwidth + width = dr * totwidth boffset, dw = 0.0, 0.0 if align == 'mid' or align == 'edge': - boffset += 0.5*totwidth + boffset += 0.5 * totwidth elif align == 'right': boffset += totwidth @@ -6307,7 +6302,7 @@ def _normalize_input(inp, ename='input'): for m, c in zip(n, color): if bottom is None: - bottom = np.zeros(len(m), float) + bottom = np.zeros(len(m)) if stacked: height = m - bottom else: @@ -6326,14 +6321,14 @@ def _normalize_input(inp, ename='input'): elif histtype.startswith('step'): # these define the perimeter of the polygon - x = np.zeros(4 * len(bins) - 3, float) - y = np.zeros(4 * len(bins) - 3, float) + x = np.zeros(4 * len(bins) - 3) + y = np.zeros(4 * len(bins) - 3) x[0:2*len(bins)-1:2], x[1:2*len(bins)-1:2] = bins, bins[:-1] x[2*len(bins)-1:] = x[1:2*len(bins)-1][::-1] if bottom is None: - bottom = np.zeros(len(bins)-1, float) + bottom = np.zeros(len(bins) - 1) y[1:2*len(bins)-1:2], y[2:2*len(bins):2] = bottom, bottom y[2*len(bins)-1:] = y[1:2*len(bins)-1][::-1]