Skip to content

Commit 57a7d3d

Browse files
committed
Return container object containing lines and arrows.
1 parent 391c24a commit 57a7d3d

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

lib/matplotlib/axes.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -6601,17 +6601,17 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
66016601
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
66026602
minlength=0.1, transform=None):
66036603
if not self._hold: self.cla()
6604-
lines = mstream.streamplot(self, x, y, u, v,
6605-
density=density,
6606-
linewidth=linewidth,
6607-
color=color,
6608-
cmap=cmap,
6609-
norm=norm,
6610-
arrowsize=arrowsize,
6611-
arrowstyle=arrowstyle,
6612-
minlength=minlength,
6613-
transform=transform)
6614-
return lines
6604+
stream_container = mstream.streamplot(self, x, y, u, v,
6605+
density=density,
6606+
linewidth=linewidth,
6607+
color=color,
6608+
cmap=cmap,
6609+
norm=norm,
6610+
arrowsize=arrowsize,
6611+
arrowstyle=arrowstyle,
6612+
minlength=minlength,
6613+
transform=transform)
6614+
return stream_container
66156615
streamplot.__doc__ = mstream.streamplot.__doc__
66166616

66176617
@docstring.dedent_interpd

lib/matplotlib/pyplot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,7 @@ def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
30553055
draw_if_interactive()
30563056
finally:
30573057
ax.hold(washold)
3058-
sci(ret[0])
3058+
sci(ret.lines)
30593059
return ret
30603060

30613061
# This function was autogenerated by boilerplate.py. Do not edit as

lib/matplotlib/streamplot.py

+23-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import matplotlib.colors as mcolors
99
import matplotlib.collections as mcollections
1010
import matplotlib.patches as patches
11+
import matplotlib.container as container
12+
1113

1214
__all__ = ['streamplot']
1315

@@ -46,11 +48,13 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
4648
*minlength* : float
4749
Minimum length of streamline in axes coordinates.
4850
49-
Returns *streamlines* : :class:`~matplotlib.collections.LineCollection`
50-
Line collection with all streamlines as a series of line segments.
51-
Currently, there is no way to differentiate between line segments
52-
on different streamlines (other than manually checking that segments
53-
are connected).
51+
Returns
52+
-------
53+
*stream_container* : StreamplotContainer
54+
Container object with attributes
55+
lines : `matplotlib.collections.LineCollection` of streamlines
56+
arrows : collection of `matplotlib.patches.FancyArrowPatch` objects
57+
repesenting arrows half-way along stream lines.
5458
"""
5559
grid = Grid(x, y)
5660
mask = StreamMask(density)
@@ -154,8 +158,20 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
154158
axes.update_datalim(((x.min(), y.min()), (x.max(), y.max())))
155159
axes.autoscale_view(tight=True)
156160

157-
arrow_collection = matplotlib.collections.PatchCollection(arrows)
158-
return lc, arrow_collection
161+
ac = matplotlib.collections.PatchCollection(arrows)
162+
stream_container = StreamplotContainer(lc, arrows=ac)
163+
return stream_container
164+
165+
166+
class StreamplotContainer(container.Container):
167+
168+
def __new__(cls, *kl, **kwargs):
169+
return tuple.__new__(cls)
170+
171+
def __init__(self, lines, arrows=None, **kwargs):
172+
self.lines = lines
173+
self.arrows = arrows
174+
container.Container.__init__(self, lines, **kwargs)
159175

160176

161177
# Coordinate definitions

0 commit comments

Comments
 (0)