SF.net SVN: matplotlib:[5820] trunk/toolkits/basemap
Revision: 5820
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5820&view=rev
Author: jswhit
Date: 2008-07-23 12:32:48 + (Wed, 23 Jul 2008)
Log Message:
---
add barbs method, barbs example.
Modified Paths:
--
trunk/toolkits/basemap/MANIFEST.in
trunk/toolkits/basemap/examples/README
trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py
Added Paths:
---
trunk/toolkits/basemap/examples/barb_demo.py
Modified: trunk/toolkits/basemap/MANIFEST.in
===
--- trunk/toolkits/basemap/MANIFEST.in 2008-07-23 03:08:41 UTC (rev 5819)
+++ trunk/toolkits/basemap/MANIFEST.in 2008-07-23 12:32:48 UTC (rev 5820)
@@ -39,6 +39,7 @@
include examples/contour_demo.py
include examples/customticks.py
include examples/quiver_demo.py
+include examples/barbs_demo.py
include examples/nytolondon.py
include examples/ortho_demo.py
include examples/geos_demo.py
Modified: trunk/toolkits/basemap/examples/README
===
--- trunk/toolkits/basemap/examples/README 2008-07-23 03:08:41 UTC (rev
5819)
+++ trunk/toolkits/basemap/examples/README 2008-07-23 12:32:48 UTC (rev
5820)
@@ -36,6 +36,8 @@
quiver_demo.py shows how to plot wind vectors on a map.
+barbs_demo.py shows how to plot wind barbs on a map.
+
randompoints.py demonstrates the use of scatter to plot randomly distributed
points on the earth.
Added: trunk/toolkits/basemap/examples/barb_demo.py
===
--- trunk/toolkits/basemap/examples/barb_demo.py
(rev 0)
+++ trunk/toolkits/basemap/examples/barb_demo.py2008-07-23 12:32:48 UTC
(rev 5820)
@@ -0,0 +1,55 @@
+from mpl_toolkits.basemap import Basemap
+import numpy as np
+import matplotlib.pyplot as plt
+
+# read in data.
+file = open('fcover.dat','r')
+ul=[];vl=[];pl=[]
+nlons=73; nlats=73
+dellat = 2.5; dellon = 5.
+for line in file.readlines():
+ l = line.replace('\n','').split()
+ ul.append(float(l[0]))
+ vl.append(float(l[1]))
+ pl.append(float(l[2]))
+u = np.reshape(np.array(ul,np.float32),(nlats,nlons))
+v = np.reshape(np.array(vl,np.float32),(nlats,nlons))
+p = np.reshape(np.array(pl,np.float32),(nlats,nlons))
+lats1 = -90.+dellat*np.arange(nlats)
+lons1 = -180.+dellon*np.arange(nlons)
+lons, lats = np.meshgrid(lons1, lats1)
+# convert from mps to knots.
+u = 1.944*u; v = 1.944*v
+
+# plot barbs in map projection coordinates.
+
+# stereogrpaphic projection.
+m = Basemap(width=1000,height=1000,lon_0=-90,lat_0=45.,lat_ts=45,
+resolution='l',projection='stere')
+x,y = m(lons,lats)
+# transform from spherical to map projection coordinates (rotation
+# and interpolation).
+nxv = 25; nyv = 25
+udat, vdat, xv, yv = m.transform_vector(u,v,lons1,lats1,nxv,nyv,returnxy=True)
+# create a figure, add an axes.
+fig=plt.figure(figsize=(8,8))
+ax = fig.add_axes([0.1,0.1,0.7,0.7])
+# plot color-filled contours over map
+levs = np.arange(960,1051,4)
+cs1 = m.contour(x,y,p,levs,colors='k',linewidths=0.5)
+cs2 = m.contourf(x,y,p,levs)
+# plot barbs.
+m.barbs(xv,yv,udat,vdat,length=6,barbcolor='k',flagcolor='r',linewidth=0.5)
+# plot colorbar for pressure
+cax = plt.axes([0.875, 0.1, 0.05, 0.7]) # setup colorbar axes.
+plt.colorbar(cax=cax) # draw colorbar
+plt.axes(ax) # make the original axes current again
+# draw coastlines
+m.drawcoastlines()
+# draw parallels
+m.drawparallels(np.arange(0,81,20),labels=[1,1,0,0])
+# draw meridians
+m.drawmeridians(np.arange(-180,0,20),labels=[0,0,0,1])
+plt.title('Surface Wind Barbs and Pressure')
+plt.show()
+
Modified: trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py
===
--- trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py 2008-07-23
03:08:41 UTC (rev 5819)
+++ trunk/toolkits/basemap/lib/mpl_toolkits/basemap/__init__.py 2008-07-23
12:32:48 UTC (rev 5820)
@@ -2890,6 +2890,44 @@
self.set_axes_limits(ax=ax)
return ret
+def barbs(self, x, y, u, v, *args, **kwargs):
+"""
+Make a wind barb plot (u, v) with on the map.
+(see matplotlib.pyplot.barbs documentation).
+
+Extra keyword ``ax`` can be used to override the default axis instance.
+
+Other \*args and \**kwargs passed on to matplotlib.pyplot.barbs
+"""
+if not kwargs.has_key('ax') and self.ax is None:
+try:
+ax = plt.gca()
+except:
+import matplotlib.pyplot as plt
+ax = plt.gca()
+elif not kwargs.has_key('ax') and self.ax is not None:
+ax = self.ax
+else:
+ax = kwargs.pop('ax')
+# allow callers to override the hold state by passing hold=True|False
+b = ax.ishold()
+h = kwargs.pop('hold',None)
+if h is not No
SF.net SVN: matplotlib:[5821] trunk/toolkits/basemap/Changelog
Revision: 5821 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5821&view=rev Author: jswhit Date: 2008-07-23 12:34:26 + (Wed, 23 Jul 2008) Log Message: --- added barbs method Modified Paths: -- trunk/toolkits/basemap/Changelog Modified: trunk/toolkits/basemap/Changelog === --- trunk/toolkits/basemap/Changelog2008-07-23 12:32:48 UTC (rev 5820) +++ trunk/toolkits/basemap/Changelog2008-07-23 12:34:26 UTC (rev 5821) @@ -1,4 +1,5 @@ version 0.99.1 (not yet released) + * added "barbs" method to draw wind barbs on the map. * added "tissot" method for generating Tissot's indicatrix (see example plot_tissot.py). * fixed processing of coastlines for gnomonic projection. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ ___ Matplotlib-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[5822] trunk/matplotlib/lib/matplotlib/cbook.py
Revision: 5822 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5822&view=rev Author: jdh2358 Date: 2008-07-23 13:16:28 + (Wed, 23 Jul 2008) Log Message: --- fixed is_scalar -- good catch david Modified Paths: -- trunk/matplotlib/lib/matplotlib/cbook.py Modified: trunk/matplotlib/lib/matplotlib/cbook.py === --- trunk/matplotlib/lib/matplotlib/cbook.py2008-07-23 12:34:26 UTC (rev 5821) +++ trunk/matplotlib/lib/matplotlib/cbook.py2008-07-23 13:16:28 UTC (rev 5822) @@ -287,7 +287,7 @@ def is_scalar(obj): 'return true if *obj* is not string like and is not iterable' -return is_string_like(obj) or not iterable(obj) +return not is_string_like(obj) or not iterable(obj) def is_numlike(obj): 'return true if *obj* looks like a number' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ ___ Matplotlib-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[5823] trunk/matplotlib/examples/pylab_examples/ barb_demo.py
Revision: 5823 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5823&view=rev Author: jdh2358 Date: 2008-07-23 13:28:32 + (Wed, 23 Jul 2008) Log Message: --- converted barb demo to unix new lines Modified Paths: -- trunk/matplotlib/examples/pylab_examples/barb_demo.py Modified: trunk/matplotlib/examples/pylab_examples/barb_demo.py === --- trunk/matplotlib/examples/pylab_examples/barb_demo.py 2008-07-23 13:16:28 UTC (rev 5822) +++ trunk/matplotlib/examples/pylab_examples/barb_demo.py 2008-07-23 13:28:32 UTC (rev 5823) @@ -1,33 +0,0 @@ -''' -Demonstration of wind barb plots -''' -import matplotlib.pyplot as plt -import numpy as np - -x = np.linspace(-5, 5, 5) -X,Y = np.meshgrid(x, x) -U, V = 12*X, 12*Y - -data = [(-1.5,.5,-6,-6), -(1,-1,-46,46), -(-3,-1,11,-11), -(1,1.5,80,80)] - -#Default parameters for arbitrary set of vectors -ax = plt.subplot(2,2,1) -ax.barbs(*zip(*data)) - -#Default parameters, uniform grid -ax = plt.subplot(2,2,2) -ax.barbs(X, Y, U, V) - -#Change parameters for arbitrary set of vectors -ax = plt.subplot(2,2,3) -ax.barbs(flagcolor='r', barbcolor=['b','g'], barb_increments=dict(half=10, -full=20, flag=100), *zip(*data)) - -#Showing colormapping with uniform grid. -ax = plt.subplot(2,2,4) -ax.barbs(X, Y, U, V, np.sqrt(U*U + V*V), fill_empty=True, rounding=False) - -plt.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ ___ Matplotlib-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[5824] trunk/matplotlib/lib/matplotlib/cbook.py
Revision: 5824 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5824&view=rev Author: dmkaplan Date: 2008-07-23 14:18:41 + (Wed, 23 Jul 2008) Log Message: --- Fix to is_scalar plus additional functions in cbook.py: less_simple_linear_interpolation isvector vector_lengths distances_along_curve path_length is_closed_polygon Modified Paths: -- trunk/matplotlib/lib/matplotlib/cbook.py Modified: trunk/matplotlib/lib/matplotlib/cbook.py === --- trunk/matplotlib/lib/matplotlib/cbook.py2008-07-23 13:28:32 UTC (rev 5823) +++ trunk/matplotlib/lib/matplotlib/cbook.py2008-07-23 14:18:41 UTC (rev 5824) @@ -287,7 +287,7 @@ def is_scalar(obj): 'return true if *obj* is not string like and is not iterable' -return not is_string_like(obj) or not iterable(obj) +return not is_string_like(obj) and not iterable(obj) def is_numlike(obj): 'return true if *obj* looks like a number' @@ -1156,6 +1156,46 @@ return result +def less_simple_linear_interpolation( x, y, xi, extrap=False ): +""" +This function provides simple (but somewhat less so than +simple_linear_interpolation) linear interpolation. This is very +inefficient linear interpolation meant to be used only for a small +number of points in relatively non-intensive use cases. + +Call signature:: + +yi = less_simple_linear_interpolation(x,y,xi) +""" +if is_scalar(xi): xi = [xi] + +x = np.asarray(x) +y = np.asarray(y) +xi = np.asarray(xi) + +s = list(y.shape) +s[0] = len(xi) +yi = np.tile( np.nan, s ) + +for ii,xx in enumerate(xi): +bb = x == xx +if np.any(bb): +jj, = np.nonzero(bb) +yi[ii] = y[jj[0]] +elif xxx[-1]: +if extrap: +yi[ii] = y[-1] +else: +jj, = np.nonzero(xhttp://moblin-contest.org/redirect.php?banner_id=100&url=/ ___ Matplotlib-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[5825] trunk/matplotlib/lib/matplotlib/backends/ __init__.py
Revision: 5825 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5825&view=rev Author: jdh2358 Date: 2008-07-23 17:09:15 + (Wed, 23 Jul 2008) Log Message: --- restored interactive_bk var to backends init -- ipython shell uses it Modified Paths: -- trunk/matplotlib/lib/matplotlib/backends/__init__.py Modified: trunk/matplotlib/lib/matplotlib/backends/__init__.py === --- trunk/matplotlib/lib/matplotlib/backends/__init__.py2008-07-23 14:18:41 UTC (rev 5824) +++ trunk/matplotlib/lib/matplotlib/backends/__init__.py2008-07-23 17:09:15 UTC (rev 5825) @@ -1,6 +1,8 @@ import matplotlib +# ipython relies on interactive_bk being defined here +from matplotlib.rcsetup import interactive_bk __all__ = ['backend','show','draw_if_interactive', 'new_figure_manager', 'backend_version'] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ ___ Matplotlib-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[5826] trunk/matplotlib/examples/pylab_examples/ barb_demo.py
Revision: 5826 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5826&view=rev Author: jdh2358 Date: 2008-07-24 02:02:01 + (Thu, 24 Jul 2008) Log Message: --- restored broken barb demo Modified Paths: -- trunk/matplotlib/examples/pylab_examples/barb_demo.py Modified: trunk/matplotlib/examples/pylab_examples/barb_demo.py === --- trunk/matplotlib/examples/pylab_examples/barb_demo.py 2008-07-23 17:09:15 UTC (rev 5825) +++ trunk/matplotlib/examples/pylab_examples/barb_demo.py 2008-07-24 02:02:01 UTC (rev 5826) @@ -0,0 +1,33 @@ +''' +Demonstration of wind barb plots +''' +import matplotlib.pyplot as plt +import numpy as np + +x = np.linspace(-5, 5, 5) +X,Y = np.meshgrid(x, x) +U, V = 12*X, 12*Y + +data = [(-1.5,.5,-6,-6), +(1,-1,-46,46), +(-3,-1,11,-11), +(1,1.5,80,80)] + +#Default parameters for arbitrary set of vectors +ax = plt.subplot(2,2,1) +ax.barbs(*zip(*data)) + +#Default parameters, uniform grid +ax = plt.subplot(2,2,2) +ax.barbs(X, Y, U, V) + +#Change parameters for arbitrary set of vectors +ax = plt.subplot(2,2,3) +ax.barbs(flagcolor='r', barbcolor=['b','g'], barb_increments=dict(half=10, +full=20, flag=100), *zip(*data)) + +#Showing colormapping with uniform grid. +ax = plt.subplot(2,2,4) +ax.barbs(X, Y, U, V, np.sqrt(U*U + V*V), fill_empty=True, rounding=False) + +plt.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ ___ Matplotlib-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[5827] trunk/matplotlib/examples/pylab_examples/ barb_demo.py
Revision: 5827
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5827&view=rev
Author: ryanmay
Date: 2008-07-24 02:28:20 + (Thu, 24 Jul 2008)
Log Message:
---
Update barb_demo.py to exercise more of the possible parameters for wind barb
plots. Replace some confusing code for passing in the data with more explicit
arrays. Also, make the data array for the arbitrary grid non-square so that
proper dimensioning can be seen. Remove mysterious windows-styles line endings.
Modified Paths:
--
trunk/matplotlib/examples/pylab_examples/barb_demo.py
Modified: trunk/matplotlib/examples/pylab_examples/barb_demo.py
===
--- trunk/matplotlib/examples/pylab_examples/barb_demo.py 2008-07-24
02:02:01 UTC (rev 5826)
+++ trunk/matplotlib/examples/pylab_examples/barb_demo.py 2008-07-24
02:28:20 UTC (rev 5827)
@@ -3,31 +3,39 @@
'''
import matplotlib.pyplot as plt
import numpy as np
-
-x = np.linspace(-5, 5, 5)
-X,Y = np.meshgrid(x, x)
-U, V = 12*X, 12*Y
-
-data = [(-1.5,.5,-6,-6),
-(1,-1,-46,46),
-(-3,-1,11,-11),
-(1,1.5,80,80)]
-
-#Default parameters for arbitrary set of vectors
-ax = plt.subplot(2,2,1)
-ax.barbs(*zip(*data))
-
-#Default parameters, uniform grid
-ax = plt.subplot(2,2,2)
-ax.barbs(X, Y, U, V)
-
-#Change parameters for arbitrary set of vectors
-ax = plt.subplot(2,2,3)
-ax.barbs(flagcolor='r', barbcolor=['b','g'], barb_increments=dict(half=10,
-full=20, flag=100), *zip(*data))
-
-#Showing colormapping with uniform grid.
-ax = plt.subplot(2,2,4)
-ax.barbs(X, Y, U, V, np.sqrt(U*U + V*V), fill_empty=True, rounding=False)
+x = np.linspace(-5, 5, 5)
+X,Y = np.meshgrid(x, x)
+U, V = 12*X, 12*Y
+
+data = [(-1.5, .5, -6, -6),
+(1, -1, -46, 46),
+(-3, -1, 11, -11),
+(1, 1.5, 80, 80),
+(0.5, 0.25, 25, 15),
+(-1.5, -0.5, -5, 40)]
+
+data = np.array(data, dtype=[('x', np.float32), ('y', np.float32),
+('u', np.float32), ('v', np.float32)])
+
+#Default parameters, uniform grid
+ax = plt.subplot(2,2,1)
+ax.barbs(X, Y, U, V)
+
+#Arbitrary set of vectors, make them longer and change the pivot point
+#(point around which they're rotated) to be the middle
+ax = plt.subplot(2,2,2)
+ax.barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle')
+
+#Showing colormapping with uniform grid. Fill the circle for an empty barb,
+#don't round the values, and change some of the size parameters
+ax = plt.subplot(2,2,3)
+ax.barbs(X, Y, U, V, np.sqrt(U*U + V*V), fill_empty=True, rounding=False,
+sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))
+
+#Change colors as well as the increments for parts of the barbs
+ax = plt.subplot(2,2,4)
+ax.barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',
+barbcolor=['b','g'], barb_increments=dict(half=10, full=20, flag=100))
+
plt.show()
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
