Skip to content

Commit b2ca027

Browse files
committed
Merge branch 'streamplot' of https://github.com/tonysyu/matplotlib into tonysyu-streamplot
2 parents 5c19722 + 6ca72da commit b2ca027

File tree

7 files changed

+627
-2
lines changed

7 files changed

+627
-2
lines changed

CHANGELOG

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

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)',
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)',
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
Y, X = np.mgrid[-3:3:100j, -3:3:100j]
5+
U = -1 - X**2 + Y
6+
V = 1 + X - Y**2
7+
speed = np.sqrt(U*U + V*V)
8+
9+
plt.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn)
10+
plt.colorbar()
11+
12+
f, (ax1, ax2) = plt.subplots(ncols=2)
13+
ax1.streamplot(X, Y, U, V)
14+
15+
lw = 5*speed/speed.max()
16+
ax2.streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw)
17+
18+
plt.show()
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Demonstrate the use of the `streamplot` function using a masked array
3+
and NaN values.
4+
"""
5+
import numpy as np
6+
import matplotlib.pyplot as plt
7+
8+
w = 3
9+
Y, X = np.mgrid[-w:w:100j, -w:w:100j]
10+
U = -1 - X**2 + Y
11+
V = 1 + X - Y**2
12+
speed = np.sqrt(U*U + V*V)
13+
14+
mask = np.zeros(U.shape, dtype=bool)
15+
mask[40:60, 40:60] = 1
16+
U = np.ma.array(U, mask=mask)
17+
U[:20, :20] = np.nan
18+
19+
plt.streamplot(X, Y, U, V, color='r')
20+
plt.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5, interpolation='nearest')
21+
22+
plt.show()
23+

lib/matplotlib/axes.py

+15
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import matplotlib.spines as mspines
3030
import matplotlib.quiver as mquiver
3131
import matplotlib.scale as mscale
32+
import matplotlib.streamplot as mstream
3233
import matplotlib.table as mtable
3334
import matplotlib.text as mtext
3435
import matplotlib.ticker as mticker
@@ -6303,6 +6304,20 @@ def quiver(self, *args, **kw):
63036304
return q
63046305
quiver.__doc__ = mquiver.Quiver.quiver_doc
63056306

6307+
def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
6308+
cmap=None, arrowsize=1, arrowstyle='-|>', minlength=0.1):
6309+
if not self._hold: self.cla()
6310+
lines = 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
6319+
streamplot.__doc__ = mstream.streamplot.__doc__
6320+
63066321
@docstring.dedent_interpd
63076322
def barbs(self, *args, **kw):
63086323
"""

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)
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)

0 commit comments

Comments
 (0)