X Tutup
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6273,28 +6273,23 @@ 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
else:
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this introduce the possibility of divide-by-zero?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l.6284 also divides by nx, so if nx is 0, we already to a divide-by-zero.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if nx is zero, then there is no data so other things are confused as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that due to l. 6176-6181 (and above), the case nx == 0 should never occur: the case where the input is empty is preprocessed to have a length of 1.

# Massage 'x' for processing.
if input_empty:
    x = np.array([[]])
else:
    x = _normalize_input(x, 'x')
nx = len(x)  # number of datasets

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

Expand All @@ -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:
Expand All @@ -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]
Expand Down
X Tutup