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

Skip to content

Commit 02cfe85

Browse files
committed
Clear up variable naming
1 parent 096ce51 commit 02cfe85

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6080,8 +6080,10 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
60806080
else:
60816081
hist_kwargs = dict(range=bin_range)
60826082

6083-
n = []
6083+
# List to store all the top coordinates of the histograms
6084+
tops = []
60846085
mlast = None
6086+
# Loop through datasets
60856087
for i in xrange(nx):
60866088
# this will automatically overwrite bins,
60876089
# so that each histogram uses the same bins
@@ -6097,21 +6099,23 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
60976099
mlast = np.zeros(len(bins)-1, m.dtype)
60986100
m += mlast
60996101
mlast[:] = m
6100-
n.append(m)
6102+
tops.append(m)
61016103

6104+
# If a stacked density plot, normalize so the area of all the stacked
6105+
# histograms together is 1
61026106
if stacked and density:
61036107
db = np.diff(bins)
6104-
for m in n:
6105-
m[:] = (m.astype(float) / db) / n[-1].sum()
6108+
for m in tops:
6109+
m[:] = (m.astype(float) / db) / tops[-1].sum()
61066110
if cumulative:
61076111
slc = slice(None)
61086112
if cbook.is_numlike(cumulative) and cumulative < 0:
61096113
slc = slice(None, None, -1)
61106114

61116115
if density:
6112-
n = [(m * np.diff(bins))[slc].cumsum()[slc] for m in n]
6116+
tops = [(m * np.diff(bins))[slc].cumsum()[slc] for m in tops]
61136117
else:
6114-
n = [m[slc].cumsum()[slc] for m in n]
6118+
tops = [m[slc].cumsum()[slc] for m in tops]
61156119

61166120
patches = []
61176121

@@ -6129,7 +6133,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
61296133

61306134
if rwidth is not None:
61316135
dr = np.clip(rwidth, 0, 1)
6132-
elif (len(n) > 1 and
6136+
elif (len(tops) > 1 and
61336137
((not stacked) or rcParams['_internal.classic_mode'])):
61346138
dr = 0.8
61356139
else:
@@ -6155,7 +6159,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
61556159
_barfunc = self.bar
61566160
bottom_kwarg = 'bottom'
61576161

6158-
for m, c in zip(n, color):
6162+
for m, c in zip(tops, color):
61596163
if bottom is None:
61606164
bottom = np.zeros(len(m))
61616165
if stacked:
@@ -6199,7 +6203,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
61996203
# For data that is normed to form a probability density,
62006204
# set to minimum data value / logbase
62016205
# (gives 1 full tick-label unit for the lowest filled bin)
6202-
ndata = np.array(n)
6206+
ndata = np.array(tops)
62036207
minimum = (np.min(ndata[ndata > 0])) / logbase
62046208
else:
62056209
# For non-normed (density = False) data,
@@ -6222,7 +6226,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
62226226
fill = (histtype == 'stepfilled')
62236227

62246228
xvals, yvals = [], []
6225-
for m in n:
6229+
for m in tops:
62266230
if stacked:
62276231
# starting point for drawing polygon
62286232
y[0] = y[1]
@@ -6285,9 +6289,9 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
62856289
p.set_label('_nolegend_')
62866290

62876291
if nx == 1:
6288-
return n[0], bins, cbook.silent_list('Patch', patches[0])
6292+
return tops[0], bins, cbook.silent_list('Patch', patches[0])
62896293
else:
6290-
return n, bins, cbook.silent_list('Lists of Patches', patches)
6294+
return tops, bins, cbook.silent_list('Lists of Patches', patches)
62916295

62926296
@_preprocess_data(replace_names=["x", "y", "weights"], label_namer=None)
62936297
def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,

0 commit comments

Comments
 (0)