Skip to content

Commit 8049c8e

Browse files
committed
Added Barbs polygon collection (similar to Quiver) for plotting wind barbs. Added corresponding helpers to Axes and pyplot as well. (examples/pylab_examples/barb_demo.py shows it off.)
svn path=/trunk/matplotlib/; revision=5819
1 parent 56827ef commit 8049c8e

File tree

7 files changed

+465
-3
lines changed

7 files changed

+465
-3
lines changed

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2008-07-22 Added Barbs polygon collection (similar to Quiver) for plotting
2+
wind barbs. Added corresponding helpers to Axes and pyplot as
3+
well. (examples/pylab_examples/barb_demo.py shows it off.) - RMM
4+
15
2008-07-21 Added scikits.delaunay as matplotlib.delaunay. Added griddata
26
function in matplotlib.mlab, with example (griddata_demo.py) in
37
pylab_examples. griddata function will use mpl_toolkits._natgrid

boilerplate.py

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def %(func)s(*args, **kwargs):
8686
'step',
8787
'vlines',
8888
'xcorr',
89+
'barbs',
8990
)
9091

9192
_misccommands = (

examples/pylab_examples/barb_demo.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'''
2+
Demonstration of wind barb plots
3+
'''
4+
import matplotlib.pyplot as plt
5+
import numpy as np
6+
7+
x = np.linspace(-5, 5, 5)
8+
X,Y = np.meshgrid(x, x)
9+
U, V = 12*X, 12*Y
10+
11+
data = [(-1.5,.5,-6,-6),
12+
(1,-1,-46,46),
13+
(-3,-1,11,-11),
14+
(1,1.5,80,80)]
15+
16+
#Default parameters for arbitrary set of vectors
17+
ax = plt.subplot(2,2,1)
18+
ax.barbs(*zip(*data))
19+
20+
#Default parameters, uniform grid
21+
ax = plt.subplot(2,2,2)
22+
ax.barbs(X, Y, U, V)
23+
24+
#Change parameters for arbitrary set of vectors
25+
ax = plt.subplot(2,2,3)
26+
ax.barbs(flagcolor='r', barbcolor=['b','g'], barb_increments=dict(half=10,
27+
full=20, flag=100), *zip(*data))
28+
29+
#Showing colormapping with uniform grid.
30+
ax = plt.subplot(2,2,4)
31+
ax.barbs(X, Y, U, V, np.sqrt(U*U + V*V), fill_empty=True, rounding=False)
32+
33+
plt.show()

examples/tests/backend_driver.py

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'axhspan_demo.py',
3434
'bar_stacked.py',
3535
'barchart_demo.py',
36+
'barb_demo.py',
3637
'boxplot_demo.py',
3738
'broken_barh.py',
3839
'barh_demo.py',

lib/matplotlib/axes.py

+9
Original file line numberDiff line numberDiff line change
@@ -5224,6 +5224,15 @@ def quiver(self, *args, **kw):
52245224
return q
52255225
quiver.__doc__ = mquiver.Quiver.quiver_doc
52265226

5227+
def barbs(self, *args, **kw):
5228+
if not self._hold: self.cla()
5229+
b = mquiver.Barbs(self, *args, **kw)
5230+
self.add_collection(b)
5231+
self.update_datalim(b.get_offsets())
5232+
self.autoscale_view()
5233+
return b
5234+
barbs.__doc__ = mquiver.Barbs.barbs_doc
5235+
52275236
def fill(self, *args, **kwargs):
52285237
"""
52295238
call signature::

lib/matplotlib/pyplot.py

+22
Original file line numberDiff line numberDiff line change
@@ -2340,6 +2340,28 @@ def xcorr(*args, **kwargs):
23402340
23412341
Additional kwargs: hold = [True|False] overrides default hold state"""
23422342

2343+
# This function was autogenerated by boilerplate.py. Do not edit as
2344+
# changes will be lost
2345+
def barbs(*args, **kwargs):
2346+
# allow callers to override the hold state by passing hold=True|False
2347+
b = ishold()
2348+
h = kwargs.pop('hold', None)
2349+
if h is not None:
2350+
hold(h)
2351+
try:
2352+
ret = gca().barbs(*args, **kwargs)
2353+
draw_if_interactive()
2354+
except:
2355+
hold(b)
2356+
raise
2357+
2358+
hold(b)
2359+
return ret
2360+
if Axes.barbs.__doc__ is not None:
2361+
barbs.__doc__ = dedent(Axes.barbs.__doc__) + """
2362+
2363+
Additional kwargs: hold = [True|False] overrides default hold state"""
2364+
23432365
# This function was autogenerated by boilerplate.py. Do not edit as
23442366
# changes will be lost
23452367
def cla(*args, **kwargs):

0 commit comments

Comments
 (0)