Skip to content

Commit 6f3053e

Browse files
committed
Add streamplot function to pyplot.
As a temporary fix, streamplot returns the last plotted streamline and arrow for use with colorbars and legends. Instead, all lines should instead be grouped into a single LineCollection, and all FancyArrowPatches should be grouped into a patch collection.
1 parent d60c9fc commit 6f3053e

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

CHANGELOG

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2012-01-08 Add axes.streamplot to plot streamlines of a velocity field. -TSY
2+
13
2011-12-29 ps and pdf markers are now stroked only if the line width
24
is nonzero for consistency with agg, fixes issue #621. - JKS
35

boilerplate.py

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def %(func)s(%(argspec)s):
8989
#'spy',
9090
'stem',
9191
'step',
92+
'streamplot',
9293
'tricontour',
9394
'tricontourf',
9495
'tripcolor',
@@ -123,6 +124,7 @@ def %(func)s(%(argspec)s):
123124
#'spy' : 'sci(%(ret)s)', ### may return image or Line2D
124125
'quiver' : 'sci(%(ret)s)',
125126
'specgram' : 'sci(%(ret)s[-1])',
127+
'streamplot' : 'sci(%(ret)s[0])',
126128
'tricontour' : 'if %(ret)s._A is not None: sci(%(ret)s)',
127129
'tricontourf': 'if %(ret)s._A is not None: sci(%(ret)s)',
128130
'tripcolor' : 'sci(%(ret)s)',

lib/matplotlib/axes.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -6307,14 +6307,15 @@ def quiver(self, *args, **kw):
63076307
def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
63086308
cmap=None, arrowsize=1, arrowstyle='-|>', minlength=0.1):
63096309
if not self._hold: self.cla()
6310-
mstream.streamplot(self, x, y, u, v,
6311-
density=density,
6312-
linewidth=linewidth,
6313-
color=color,
6314-
cmap=cmap,
6315-
arrowsize=arrowsize,
6316-
arrowstyle=arrowstyle,
6317-
minlength=minlength)
6310+
lines, arrows = mstream.streamplot(self, x, y, u, v,
6311+
density=density,
6312+
linewidth=linewidth,
6313+
color=color,
6314+
cmap=cmap,
6315+
arrowsize=arrowsize,
6316+
arrowstyle=arrowstyle,
6317+
minlength=minlength)
6318+
return lines, arrows
63186319
streamplot.__doc__ = mstream.streamplot.__doc__
63196320

63206321
@docstring.dedent_interpd

lib/matplotlib/pyplot.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -2615,15 +2615,15 @@ def specgram(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, window=mlab.win
26152615
# This function was autogenerated by boilerplate.py. Do not edit as
26162616
# changes will be lost
26172617
@autogen_docstring(Axes.stem)
2618-
def stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-', hold=None):
2618+
def stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-', bottom=None, label=None, hold=None):
26192619
ax = gca()
26202620
# allow callers to override the hold state by passing hold=True|False
26212621
washold = ax.ishold()
26222622

26232623
if hold is not None:
26242624
ax.hold(hold)
26252625
try:
2626-
ret = ax.stem(x, y, linefmt, markerfmt, basefmt)
2626+
ret = ax.stem(x, y, linefmt, markerfmt, basefmt, bottom, label)
26272627
draw_if_interactive()
26282628
finally:
26292629
ax.hold(washold)
@@ -2648,6 +2648,24 @@ def step(x, y, *args, **kwargs):
26482648

26492649
return ret
26502650

2651+
# This function was autogenerated by boilerplate.py. Do not edit as
2652+
# changes will be lost
2653+
@autogen_docstring(Axes.streamplot)
2654+
def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None, arrowsize=1, arrowstyle='-|>', minlength=0.10000000000000001, hold=None):
2655+
ax = gca()
2656+
# allow callers to override the hold state by passing hold=True|False
2657+
washold = ax.ishold()
2658+
2659+
if hold is not None:
2660+
ax.hold(hold)
2661+
try:
2662+
ret = ax.streamplot(x, y, u, v, density, linewidth, color, cmap, arrowsize, arrowstyle, minlength)
2663+
draw_if_interactive()
2664+
finally:
2665+
ax.hold(washold)
2666+
sci(ret[0])
2667+
return ret
2668+
26512669
# This function was autogenerated by boilerplate.py. Do not edit as
26522670
# changes will be lost
26532671
@autogen_docstring(Axes.tricontour)

lib/matplotlib/streamplot.py

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=1, color='k', cmap=None,
136136

137137
axes.update_datalim(((x.min(), y.min()), (x.max(), y.max())))
138138
axes.autoscale_view(tight=True)
139+
# TODO: Currently this returns only the last streamline and arrow patch.
140+
return lc, p
139141

140142

141143
# Coordinate definitions

0 commit comments

Comments
 (0)