Exemple #1
0
 def _parse_args(self, *args):
     X, Y, U, V, C = [None]*5
     args = list(args)
     if len(args) == 3 or len(args) == 5:
         C = nx.ravel(args.pop(-1))
         #print 'in parse_args, C:', C
     V = nx.ma.asarray(args.pop(-1))
     U = nx.ma.asarray(args.pop(-1))
     nn = nx.shape(U)
     nc = nn[0]
     nr = 1
     if len(nn) > 1:
         nr = nn[1]
     if len(args) == 2:
         X, Y = [nx.ravel(a) for a in args]
         if len(X) == nc and len(Y) == nr:
             X, Y = [nx.ravel(a) for a in meshgrid(X, Y)]
     else:
         X, Y = [nx.ravel(a) for a in meshgrid(nx.arange(nc), nx.arange(nr))]
     return X, Y, U, V, C
Exemple #2
0
def get_test_data(delta=0.05):
    from matplotlib.mlab import meshgrid, bivariate_normal
    x = y = npy.arange(-3.0, 3.0, delta)
    X, Y = meshgrid(x,y)

    Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
    Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
    Z = Z2-Z1

    X = X * 10
    Y = Y * 10
    Z = Z * 500
    return X,Y,Z
Exemple #3
0
    def makegrid(self,nx,ny,returnxy=False):
        """
 return arrays of shape (ny,nx) containing lon,lat coordinates of
 an equally spaced native projection grid.
 if returnxy=True, the x,y values of the grid are returned also.
        """
        x = linspace(self.llcrnrx,self.urcrnrx,nx)
        y = linspace(self.llcrnry,self.urcrnry,ny)
        x, y = meshgrid(x, y)
        lons, lats = self(x, y, inverse=True)
        if returnxy:
            return lons, lats, x, y
        else:
            return lons, lats
Exemple #4
0
    def makegrid(self, nx, ny, returnxy=False):
        """
 return arrays of shape (ny,nx) containing lon,lat coordinates of
 an equally spaced native projection grid.
 if returnxy=True, the x,y values of the grid are returned also.
        """
        x = linspace(self.llcrnrx, self.urcrnrx, nx)
        y = linspace(self.llcrnry, self.urcrnry, ny)
        x, y = meshgrid(x, y)
        lons, lats = self(x, y, inverse=True)
        if returnxy:
            return lons, lats, x, y
        else:
            return lons, lats
Exemple #5
0
 def add_lines(self, levels, colors, linewidths):
     """
     Draw lines on the colorbar.
     """
     N = len(levels)
     y = self._locate(levels)
     x = nx.array([0.0, 1.0])
     X, Y = meshgrid(x, y)
     if self.orientation == "vertical":
         xy = [zip(X[i], Y[i]) for i in range(N)]
     else:
         xy = [zip(Y[i], X[i]) for i in range(N)]
     col = LineCollection(xy, linewidths=linewidths)
     self.lines = col
     col.set_color(colors)
     self.ax.add_collection(col)
Exemple #6
0
 def add_lines(self, levels, colors, linewidths):
     '''
     Draw lines on the colorbar.
     '''
     N = len(levels)
     y = self._locate(levels)
     x = nx.array([0.0, 1.0])
     X, Y = meshgrid(x, y)
     if self.orientation == 'vertical':
         xy = [zip(X[i], Y[i]) for i in range(N)]
     else:
         xy = [zip(Y[i], X[i]) for i in range(N)]
     col = LineCollection(xy, linewidths=linewidths)
     self.lines = col
     col.set_color(colors)
     self.ax.add_collection(col)
Exemple #7
0
    def init_plot_data(self):
        a = self.fig.add_subplot(111)
        
        x = numerix.arange(120.0)*2*numerix.pi/60.0
        y = numerix.arange(100.0)*2*numerix.pi/50.0
        self.x, self.y = meshgrid(x, y)
        z = numerix.sin(self.x) + numerix.cos(self.y)
        self.im = a.imshow( z, cmap=cm.jet)#, interpolation='nearest')
        
        zmax = numerix.max(numerix.max(z))-ERR_TOL
        ymax_i, xmax_i = numerix.nonzero(
            numerix.greater_equal(z, zmax))
        if self.im.origin == 'upper':
            ymax_i = z.shape[0]-ymax_i
        self.lines = a.plot(xmax_i,ymax_i,'ko')

        self.toolbar.update() # Not sure why this is needed - ADS
Exemple #8
0
 def _mesh(self):
     """
     Return X,Y, the coordinate arrays for the colorbar pcolormesh.
     These are suitable for a vertical colorbar; swapping and
     transposition for a horizontal colorbar are done outside
     this function.
     """
     x = nx.array([0.0, 1.0])
     if self.spacing == "uniform":
         y = self._uniform_y(self._central_N())
     else:
         y = self._proportional_y()
     self._y = y
     X, Y = meshgrid(x, y)
     if self.extend in ("min", "both"):
         X[0, :] = 0.5
     if self.extend in ("max", "both"):
         X[-1, :] = 0.5
     return X, Y
Exemple #9
0
 def _mesh(self):
     '''
     Return X,Y, the coordinate arrays for the colorbar pcolormesh.
     These are suitable for a vertical colorbar; swapping and
     transposition for a horizontal colorbar are done outside
     this function.
     '''
     x = nx.array([0.0, 1.0])
     if self.spacing == 'uniform':
         y = self._uniform_y(self._central_N())
     else:
         y = self._proportional_y()
     self._y = y
     X, Y = meshgrid(x, y)
     if self.extend in ('min', 'both'):
         X[0, :] = 0.5
     if self.extend in ('max', 'both'):
         X[-1, :] = 0.5
     return X, Y
Exemple #10
0
 def testThinLens(self):
     import matplotlib
     matplotlib.use('AGG')
     import matplotlib.mlab as ml
     import pylab as pl
     import time
     lens = ThinLens(150.0, 100.0)
     gbOut = lens*self.gb
     self.assertAlmostEqual(gbOut._z0, 250.0)
     (w1, z1) = lens.transformBeamWaist((self.gb._w0, self.gb._z0), self.gb._k)
     self.assertAlmostEqual(gbOut._w0, w1)
     
     f = 150.0
     lens = ThinLens(f, 0)
     w0, z0 = ml.meshgrid([4.0, 8.0, 16.0], np.arange(-3*f, f))
     (w1, z1) = lens.transformBeamWaist((w0, z0), self.gb._k)
     #h = pl.figure()
     pl.plot(z0/f, z1/f)
     pl.grid()
     pl.xlabel('d_{in} [f]')
     pl.ylabel('d_{out} [f]')
     pl.savefig('testThinLens1.png')
     time.sleep(0.1)
     pl.close('all')
Exemple #11
0
lons = nx.array(load('etopo20lons.gz'),'d')
lats = nx.array(load('etopo20lats.gz'),'d')
# create figure.
fig = Figure()
canvas = FigureCanvas(fig)
# create axes instance, leaving room for colorbar at bottom.
ax = fig.add_axes([0.125,0.175,0.75,0.75])
# create Basemap instance for Robinson projection.
# set 'ax' keyword so pylab won't be imported.
m = Basemap(projection='robin',lon_0=0.5*(lons[0]+lons[-1]),ax=ax)
# reset figure size to have same aspect ratio as map.
# fig will be 8 inches wide.
# (don't use createfigure, since that imports pylab).
fig.set_figsize_inches((8,m.aspect*8.))
# make filled contour plot.
x, y = m(*meshgrid(lons, lats))
cs = m.contourf(x,y,etopo,30,cmap=cm.jet)
# draw coastlines.
m.drawcoastlines()
# draw a line around the map region.
m.drawmapboundary()
# draw parallels and meridians.
m.drawparallels(nx.arange(-60.,90.,30.),labels=[1,0,0,0],fontsize=10)
m.drawmeridians(nx.arange(0.,420.,60.),labels=[0,0,0,1],fontsize=10)
# add a title.
ax.set_title('Robinson Projection')
# add a colorbar.
cax = fig.add_axes([0.125, 0.05, 0.75, 0.05],frameon=False)
fig.colorbar(cs, cax=cax, tickfmt='%d', orientation='horizontal',clabels=cs.levels[::3]) 
# save image (width 800 pixels with dpi=100 and fig width 8 inches).
canvas.print_figure('simpletest',dpi=100)
Exemple #12
0
#!/usr/bin/env python
"""
pcolormesh uses a QuadMesh, a faster generalization of pcolor, but
with some restrictions.
"""

from matplotlib.mlab import linspace, meshgrid
import matplotlib.numerix as nx
from pylab import figure,show
import matplotlib.numerix.ma as ma
from matplotlib import cm, colors

n = 56
x = linspace(-1.5,1.5,n)
X,Y = meshgrid(x,x);
Qx = nx.cos(Y) - nx.cos(X)
Qz = nx.sin(Y) + nx.sin(X)
Qx = (Qx + 1.1)
Z = nx.sqrt(X**2 + Y**2)/5;
Z = (Z - nx.mlab.amin(Z)) / (nx.mlab.amax(Z) - nx.mlab.amin(Z))

# The color array can include masked values:
Zm = ma.masked_where(nx.fabs(Qz) < 0.5*nx.mlab.amax(Qz), Z)


fig = figure()
ax = fig.add_subplot(121)
ax.pcolormesh(Qx,Qz,Z)
ax.set_title('Without masked values')

ax = fig.add_subplot(122)
Exemple #13
0
from matplotlib.mlab import linspace, meshgrid
import matplotlib.numerix as nx
from pylab import figure,show

n = 56
x = linspace(-1.5,1.5,n)
X,Y = meshgrid(x,x);
Qx = nx.cos(Y) - nx.cos(X)
Qz = nx.sin(Y) + nx.sin(X)
Qx = (Qx + 1.1)
Z = nx.sqrt(X**2 + Y**2)/5;
Z = (Z - nx.mlab.amin(Z)) / (nx.mlab.amax(Z) - nx.mlab.amin(Z))

fig = figure()
ax = fig.add_subplot(111)
ax.pcolormesh(Qx,Qz,Z)
show()