Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f550f8b

Browse files
authored
Merge pull request #7481 from anntzer/cleanup-hist
MNT: Minor cleanup of hist().
2 parents 5e66acc + 75ef70b commit f550f8b

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6273,28 +6273,23 @@ def _normalize_input(inp, ename='input'):
62736273
totwidth = np.diff(bins)
62746274

62756275
if rwidth is not None:
6276-
dr = min(1.0, max(0.0, rwidth))
6276+
dr = np.clip(rwidth, 0, 1)
62776277
elif (len(n) > 1 and
62786278
((not stacked) or rcParams['_internal.classic_mode'])):
62796279
dr = 0.8
62806280
else:
62816281
dr = 1.0
62826282

62836283
if histtype == 'bar' and not stacked:
6284-
width = dr*totwidth/nx
6284+
width = dr * totwidth / nx
62856285
dw = width
6286-
6287-
if nx > 1:
6288-
boffset = -0.5*dr*totwidth*(1.0-1.0/nx)
6289-
else:
6290-
boffset = 0.0
6291-
stacked = False
6286+
boffset = -0.5 * dr * totwidth * (1 - 1 / nx)
62926287
elif histtype == 'barstacked' or stacked:
6293-
width = dr*totwidth
6288+
width = dr * totwidth
62946289
boffset, dw = 0.0, 0.0
62956290

62966291
if align == 'mid' or align == 'edge':
6297-
boffset += 0.5*totwidth
6292+
boffset += 0.5 * totwidth
62986293
elif align == 'right':
62996294
boffset += totwidth
63006295

@@ -6307,7 +6302,7 @@ def _normalize_input(inp, ename='input'):
63076302

63086303
for m, c in zip(n, color):
63096304
if bottom is None:
6310-
bottom = np.zeros(len(m), float)
6305+
bottom = np.zeros(len(m))
63116306
if stacked:
63126307
height = m - bottom
63136308
else:
@@ -6326,14 +6321,14 @@ def _normalize_input(inp, ename='input'):
63266321

63276322
elif histtype.startswith('step'):
63286323
# these define the perimeter of the polygon
6329-
x = np.zeros(4 * len(bins) - 3, float)
6330-
y = np.zeros(4 * len(bins) - 3, float)
6324+
x = np.zeros(4 * len(bins) - 3)
6325+
y = np.zeros(4 * len(bins) - 3)
63316326

63326327
x[0:2*len(bins)-1:2], x[1:2*len(bins)-1:2] = bins, bins[:-1]
63336328
x[2*len(bins)-1:] = x[1:2*len(bins)-1][::-1]
63346329

63356330
if bottom is None:
6336-
bottom = np.zeros(len(bins)-1, float)
6331+
bottom = np.zeros(len(bins) - 1)
63376332

63386333
y[1:2*len(bins)-1:2], y[2:2*len(bins):2] = bottom, bottom
63396334
y[2*len(bins)-1:] = y[1:2*len(bins)-1][::-1]

0 commit comments

Comments
 (0)