def ezquiver( func, domain=np.array([0, 1, 0, 1]).reshape(1, -1), resolution=np.array([30, 29]).reshape(1, -1), ax=None, *args, **kwargs ): """Vectorized quiver for functions with vector args. @param func: function handle @param domain: rectangular plotting domain = [xmin, xmax, ymin, ymax] @param resolution: grid spacing = [nx, ny] @param ax: axes object handle @param args: positional arguments forwarded to func @param kwargs: key-value args for func """ if ax is None: ax = newax() q = domain2vec(domain, resolution) v = feval(func, q, **kwargs) quiver(ax, q, v)
def ezcontour(func, ax, domain, resolution, values, **kwargs): """Vectorized easy contour, for functions accepting vector arguments. @param ax: axes object handle @param func: function handle @param domain: rectangular plotting domain @type domain: [xmin, xmax, ymin, ymax] @param resolution: grid spacing @type resolution: [nx, ny] @param values: level set values @type values: [v1, v2, ..., vN] @param kwargs: additional arguments for input to func """ # which axes ? if 0 in ax.shape: warn("vezcontour:axes", "Axes object handle ax is empty, no plot.") return # which domain ? if not domain: domain = np.array([0, 1, 0, 1]).reshape(1, -1) # at what grid resolution ? if not resolution: resolution = np.array([30, 29]).reshape(1, -1) else: if 0 in resolution.shape: resolution = np.array([30, 29]).reshape(1, -1) # which level sets ? if not values: values = np.array([]) # compute surface q, X, Y = domain2vec(domain, resolution) # nargout=3 f = feval(func, q, **kwargs) Z = vec2meshgrid(f, X) # default level set values ? if 0 in values.shape: plt.contour(ax, X, Y, Z) else: plt.contour(ax, X, Y, Z, values) return
def ezsurf(func, domain, resolution, ax, **kwargs): """Vectorized ezsurf, for functions accepting vector arguments. input ax = axes object handle func = function handle optional input domain = rectangular plotting domain = [xmin, xmax, ymin, ymax] resolution = grid spacing = [nx, ny] varargin = additional arguments for input to func @return (q, f) where: - q = domain points - f = function values at q """ # which axes ? if 0 in ax.shape: warn("vezsurf:axes", "Axes object handle ax is empty, no plot.") return varargout # which domain ? if not domain: domain = np.array([0, 1, 0, 1]).reshape(1, -1) # at what grid resolution ? if not resolution: resolution = np.array([30, 29]).reshape(1, -1) else: if 0 in resolution.shape: resolution = np.array([30, 29]).reshape(1, -1) q = domain2vec(domain, resolution) f = feval(func, q, varargin[:]) vsurf(ax, q, f, resolution) if nargout > 0: varargout[0, 0] = q varargout[0, 1] = f return varargout