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

Skip to content

Streamplot: clean up handling of masks, eliminate warning in test. #3101

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
Jun 1, 2014
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
13 changes: 5 additions & 8 deletions lib/matplotlib/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
if use_multicolor_lines:
assert color.shape == grid.shape
line_colors = []
if np.any(np.isnan(color)):
color = np.ma.array(color, mask=np.isnan(color))
color = np.ma.masked_invalid(color)
else:
line_kw['color'] = color
arrow_kw['color'] = color
Expand All @@ -112,10 +111,8 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
assert u.shape == grid.shape
assert v.shape == grid.shape

if np.any(np.isnan(u)):
u = np.ma.array(u, mask=np.isnan(u))
if np.any(np.isnan(v)):
v = np.ma.array(v, mask=np.isnan(v))
u = np.ma.masked_invalid(u)
v = np.ma.masked_invalid(v)

integrate = get_integrator(u, v, dmap, minlength)

Expand Down Expand Up @@ -160,7 +157,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,

if use_multicolor_lines:
color_values = interpgrid(color, tgx, tgy)[:-1]
line_colors.extend(color_values)
line_colors.append(color_values)
arrow_kw['color'] = cmap(norm(color_values[n]))

p = patches.FancyArrowPatch(arrow_tail,
Expand All @@ -174,7 +171,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
transform=transform,
**line_kw)
if use_multicolor_lines:
lc.set_array(np.asarray(line_colors))
lc.set_array(np.ma.hstack(line_colors))
lc.set_cmap(cmap)
lc.set_norm(norm)
axes.add_collection(lc)
Expand Down