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
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
def __init__(self, ax, labels, actives): """ Add check buttons to axes.Axes instance ax labels is a len(buttons) list of labels as strings actives is a len(buttons) list of booleans indicating whether the button is active """ ax.set_xticks([]) ax.set_yticks([]) ax.set_navigate(False) dy = 1./(len(labels)+1) ys = linspace(1-dy, dy, len(labels)) cnt = 0 axcolor = ax.get_axis_bgcolor() self.labels = [] self.lines = [] self.rectangles = [] lineparams = {'color':'k', 'linewidth':1.25, 'transform':ax.transAxes, 'solid_capstyle':'butt'} for y, label in zip(ys, labels): t = ax.text(0.25, y, label, transform=ax.transAxes, horizontalalignment='left', verticalalignment='center') w, h = dy/2., dy/2. x, y = 0.05, y-h/2. p = Rectangle(xy=(x,y), width=w, height=h, facecolor=axcolor, transform=ax.transAxes) l1 = Line2D([x, x+w], [y+h, y], **lineparams) l2 = Line2D([x, x+w], [y, y+h], **lineparams) l1.set_visible(actives[cnt]) l2.set_visible(actives[cnt]) self.labels.append(t) self.rectangles.append(p) self.lines.append((l1,l2)) ax.add_patch(p) ax.add_line(l1) ax.add_line(l2) cnt += 1 ax.figure.canvas.mpl_connect('button_press_event', self._clicked) self.ax = ax self.cnt = 0 self.observers = {}
def _uniform_y(self, N): """ Return colorbar data coordinates for N uniformly spaced boundaries, plus ends if required. """ if self.extend == "neither": y = linspace(0, 1, N) else: if self.extend == "both": y = nx.zeros(N + 2, "d") y[0] = -0.05 y[-1] = 1.05 elif self.extend == "min": y = nx.zeros(N + 1, "d") y[0] = -0.05 else: y = nx.zeros(N + 1, "d") y[-1] = 1.05 y[self._inside] = linspace(0, 1, N) return y
def _uniform_y(self, N): ''' Return colorbar data coordinates for N uniformly spaced boundaries, plus ends if required. ''' if self.extend == 'neither': y = linspace(0, 1, N) else: if self.extend == 'both': y = nx.zeros(N + 2, 'd') y[0] = -0.05 y[-1] = 1.05 elif self.extend == 'min': y = nx.zeros(N + 1, 'd') y[0] = -0.05 else: y = nx.zeros(N + 1, 'd') y[-1] = 1.05 y[self._inside] = linspace(0, 1, N) return y
def __init__(self, ax, labels, active=0, activecolor='blue'): """ Add radio buttons to axes.Axes instance ax labels is a len(buttons) list of labels as strings active is the index into labels for the button that is active activecolor is the color of the button when clicked """ self.activecolor = activecolor ax.set_xticks([]) ax.set_yticks([]) ax.set_navigate(False) dy = 1./(len(labels)+1) ys = linspace(1-dy, dy, len(labels)) cnt = 0 axcolor = ax.get_axis_bgcolor() self.labels = [] self.circles = [] for y, label in zip(ys, labels): t = ax.text(0.25, y, label, transform=ax.transAxes, horizontalalignment='left', verticalalignment='center') if cnt==active: facecolor = activecolor else: facecolor = axcolor p = Circle(xy=(0.15, y), radius=0.05, facecolor=facecolor, transform=ax.transAxes) self.labels.append(t) self.circles.append(p) ax.add_patch(p) cnt += 1 ax.figure.canvas.mpl_connect('button_press_event', self._clicked) self.ax = ax self.cnt = 0 self.observers = {}
def get_colours(n): """ Return n pastel colours. """ base = asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) if n <= 3: return base[0:n] # how many new colours to we need to insert between # red and green and between green and blue? needed = (((n - 3) + 1) / 2, (n - 3) / 2) colours = [] for start in (0, 1): for x in linspace(0, 1, needed[start] + 2): colours.append((base[start] * (1.0 - x)) + (base[start + 1] * x)) return [pastel(c) for c in colours[0:n]]
def get_colours(n): """ Return n pastel colours. """ base = asarray([[1,0,0], [0,1,0], [0,0,1]]) if n <= 3: return base[0:n] # how many new colours to we need to insert between # red and green and between green and blue? needed = (((n - 3) + 1) / 2, (n - 3) / 2) colours = [] for start in (0, 1): for x in linspace(0, 1, needed[start]+2): colours.append((base[start] * (1.0 - x)) + (base[start+1] * x)) return [pastel(c) for c in colours[0:n]]
#!/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)
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()