def vquiver(varu, varv, varc=None, axes=None, lblx=True, lbly=True, label=True, transpose=None, **kwargs): # {{{ U = varu.squeeze() V = varv.squeeze() assert U.naxes == 2 and V.naxes == 2, 'Variables to quiver must have two non-degenerate axes.' assert U.axes == V.axes, 'Variables U and V must have the same axes.' X, Y = U.axes if varc is not None: C = varc.squeeze() assert U.axes == C.axes, 'Color values must have same axes as U and V' from pygeode.axis import Lat, Lon # If a vertical axis is present transpose the plot from pygeode.axis import ZAxis, Lat, Lon if transpose is None: if isinstance(X, ZAxis): X, Y = Y, X if isinstance(X, Lat) and isinstance(Y, Lon): X, Y = Y, X elif transpose: X, Y = Y, X x = scalevalues(X) y = scalevalues(Y) u = scalevalues(U.transpose(Y, X)) v = scalevalues(V.transpose(Y, X)) if varc is not None: c = scalevalues(C.transpose(Y, X)) map = kwargs.pop('map', None) if axes is None: if isinstance(X, Lon) and isinstance(Y, Lat) and map is not False: axes = build_basemap(x, y, map = map, **kwargs) else: axes = wr.AxesWrapper() if varc is not None: axes.quiver(x, y, u, v, c, **kwargs) else: axes.quiver(x, y, u, v, **kwargs) # Apply the custom axes args if label: axes.pad = (0.1, 0.1, 0.1, 0.1) if wr.isbasemapaxis(axes): decorate_basemap(axes, map = map, **kwargs) else: set_xaxis(axes, X, lblx) set_yaxis(axes, Y, lbly) plt = _getplotatts(varu) axes.setp(title = _buildvartitle(varu.axes, **plt)) return axes
def vcontour(var, clevs=None, clines=None, axes=None, lblx=True, lbly=True, label=True, transpose=None, **kwargs): # {{{ Z = var.squeeze() assert Z.naxes == 2, 'Variable to contour must have two non-degenerate axes.' X, Y = Z.axes # If a vertical axis is present transpose the plot from pygeode.axis import ZAxis, Lat, Lon if transpose is None: if isinstance(X, ZAxis): X, Y = Y, X if isinstance(X, Lat) and isinstance(Y, Lon): X, Y = Y, X elif transpose: X, Y = Y, X x = scalevalues(X) y = scalevalues(Y) z = scalevalues(Z.transpose(Y, X)) if axes is None: if isinstance(X, Lon) and isinstance(Y, Lat) and kwargs.get('map', None) is not False: axes = build_basemap(x, y, **kwargs) else: axes = wr.AxesWrapper() if clevs is None and clines is None: # If both clevs and clines are None, use default axes.contourf(x, y, z, 21, **kwargs) if not clevs is None: axes.contourf(x, y, z, clevs, **kwargs) # Special case; if plotting both filled and unfilled contours # with a single call, set the color of the latter to black kwargs['colors'] = 'k' kwargs['cmap'] = None if not clines is None: axes.contour(x, y, z, clines, **kwargs) # Apply the custom axes args if label: axes.pad = (0.1, 0.1, 0.1, 0.1) if wr.isbasemapaxis(axes): decorate_basemap(axes, **kwargs) else: axes.pad = (0.1, 0.1, 0.1, 0.1) set_xaxis(axes, X, lblx) set_yaxis(axes, Y, lbly) plt = _getplotatts(var) axes.setp(title = _buildvartitle(var.axes, **plt)) return axes