8000 Avoid some uses of np.isscalar. by anntzer · Pull Request #12070 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Avoid some uses of np.isscalar. #12070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2018
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions examples/lines_bars_and_markers/filled_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def filled_hist(ax, edges, values, bottoms=None, orientation='v',
lb=len(edges), lv=len(values)))

if bottoms is None:
bottoms = np.zeros_like(values)
if np.isscalar(bottoms):
bottoms = np.ones_like(values) * bottoms
bottoms = 0
bottoms = np.broadcast_to(bottoms, values.shape)

values = np.r_[values, values[-1]]
bottoms = np.r_[bottoms, bottoms[-1]]
Expand Down
15 changes: 6 additions & 9 deletions lib/matplotlib/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,12 @@ class StreamMask(object):
"""

def __init__(self, density):
if np.isscalar(density):
if density <= 0:
raise ValueError("If a scalar, 'density' must be positive")
self.nx = self.ny = int(30 * density)
else:
if len(density) != 2:
raise ValueError("'density' can have at maximum 2 dimensions")
self.nx = int(30 * density[0])
self.ny = int(30 * density[1])
try:
self.nx, self.ny = (30 * np.broadcast_to(density, 2)).astype(int)
except ValueError:
raise ValueError("'density' must be a scalar or be of length 2")
if self.nx < 0 or self.ny < 0:
raise ValueError("'density' must be positive")
self._mask = np.zeros((self.ny, self.nx))
self.shape = self._mask.shape

Expand Down
0