Skip to content
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

Return arrow collection as 2nd argument of streamplot. #803

Merged
merged 4 commits into from Sep 2, 2012
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/matplotlib/axes.py
Expand Up @@ -6601,17 +6601,17 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>', cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
minlength=0.1, transform=None): minlength=0.1, transform=None):
if not self._hold: self.cla() if not self._hold: self.cla()
lines = mstream.streamplot(self, x, y, u, v, stream_container = mstream.streamplot(self, x, y, u, v,
density=density, density=density,
linewidth=linewidth, linewidth=linewidth,
color=color, color=color,
cmap=cmap, cmap=cmap,
norm=norm, norm=norm,
arrowsize=arrowsize, arrowsize=arrowsize,
arrowstyle=arrowstyle, arrowstyle=arrowstyle,
minlength=minlength, minlength=minlength,
transform=transform) transform=transform)
return lines return stream_container
streamplot.__doc__ = mstream.streamplot.__doc__ streamplot.__doc__ = mstream.streamplot.__doc__


@docstring.dedent_interpd @docstring.dedent_interpd
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/pyplot.py
Expand Up @@ -3055,7 +3055,7 @@ def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
draw_if_interactive() draw_if_interactive()
finally: finally:
ax.hold(washold) ax.hold(washold)
sci(ret) sci(ret.lines)
return ret return ret


# This function was autogenerated by boilerplate.py. Do not edit as # This function was autogenerated by boilerplate.py. Do not edit as
Expand Down
30 changes: 24 additions & 6 deletions lib/matplotlib/streamplot.py
Expand Up @@ -9,6 +9,7 @@
import matplotlib.collections as mcollections import matplotlib.collections as mcollections
import matplotlib.patches as patches import matplotlib.patches as patches



__all__ = ['streamplot'] __all__ = ['streamplot']




Expand Down Expand Up @@ -46,11 +47,16 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
*minlength* : float *minlength* : float
Minimum length of streamline in axes coordinates. Minimum length of streamline in axes coordinates.


Returns *streamlines* : :class:`~matplotlib.collections.LineCollection` Returns
Line collection with all streamlines as a series of line segments. -------
Currently, there is no way to differentiate between line segments *stream_container* : StreamplotSet
on different streamlines (other than manually checking that segments Container object with attributes
are connected). lines : `matplotlib.collections.LineCollection` of streamlines
arrows : collection of `matplotlib.patches.FancyArrowPatch` objects
repesenting arrows half-way along stream lines.
This container will probably change in the future to allow changes to
the colormap, alpha, etc. for both lines and arrows, but these changes
should be backward compatible.
""" """
grid = Grid(x, y) grid = Grid(x, y)
mask = StreamMask(density) mask = StreamMask(density)
Expand Down Expand Up @@ -108,6 +114,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
cmap = cm.get_cmap(cmap) cmap = cm.get_cmap(cmap)


streamlines = [] streamlines = []
arrows = []
for t in trajectories: for t in trajectories:
tgx = np.array(t[0]) tgx = np.array(t[0])
tgy = np.array(t[1]) tgy = np.array(t[1])
Expand Down Expand Up @@ -139,6 +146,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
transform=transform, transform=transform,
**arrow_kw) **arrow_kw)
axes.add_patch(p) axes.add_patch(p)
arrows.append(p)


lc = mcollections.LineCollection(streamlines, lc = mcollections.LineCollection(streamlines,
transform=transform, transform=transform,
Expand All @@ -151,7 +159,17 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,


axes.update_datalim(((x.min(), y.min()), (x.max(), y.max()))) axes.update_datalim(((x.min(), y.min()), (x.max(), y.max())))
axes.autoscale_view(tight=True) axes.autoscale_view(tight=True)
return lc
ac = matplotlib.collections.PatchCollection(arrows)
stream_container = StreamplotSet(lc, ac)
return stream_container


class StreamplotSet(object):

def __init__(self, lines, arrows, **kwargs):
self.lines = lines
self.arrows = arrows




# Coordinate definitions # Coordinate definitions
Expand Down