def fill_between(self, x, y1, y2=0, where=None, **kwargs): """ Make filled polygons between two curves (y1 and y2) where ``where==True``. :param x: (*array_like*) An N-length array of the x data. :param y1: (*array_like*) An N-length array (or scalar) of the y data. :param y2: (*array_like*) An N-length array (or scalar) of the y data. :param where: (*array_like*) If None, default to fill between everywhere. If not None, it is an N-length boolean array and the fill will only happen over the regions where ``where==True``. """ #Get dataset global gca #Add data series label = kwargs.pop('label', 'S_0') dn = len(x) xdata = plotutil.getplotdata(x) if isinstance(y1, (int, long, float)): yy = [] for i in range(dn): yy.append(y1) y1 = np.array(yy)._array else: y1 = plotutil.getplotdata(y1) if isinstance(y2, (int, long, float)): yy = [] for i in range(dn): yy.append(y2) y2 = np.array(yy)._array else: y2 = plotutil.getplotdata(y2) if not where is None: if isinstance(where, (tuple, list)): where = np.array(where) where = where.asarray() #Set plot data styles if not 'fill' in kwargs: kwargs['fill'] = True if not 'edge' in kwargs: kwargs['edge'] = False pb, isunique = plotutil.getlegendbreak('polygon', **kwargs) pb.setCaption(label) #Create graphics offset = kwargs.pop('offset', 0) zdir = kwargs.pop('zdir', 'z') if zdir == 'xy': y = kwargs.pop('y', x) ydata = plotutil.getplotdata(y) graphics = GraphicFactory.createFillBetweenPolygons(xdata, ydata, y1, y2, where, pb, \ offset, zdir) else: graphics = GraphicFactory.createFillBetweenPolygons(xdata, y1, y2, where, pb, \ offset, zdir) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def fill_between(self, x, y1, y2=0, where=None, **kwargs): """ Make filled polygons between two curves (y1 and y2) where ``where==True``. :param x: (*array_like*) An N-length array of the x data. :param y1: (*array_like*) An N-length array (or scalar) of the y data. :param y2: (*array_like*) An N-length array (or scalar) of the y data. :param where: (*array_like*) If None, default to fill between everywhere. If not None, it is an N-length boolean array and the fill will only happen over the regions where ``where==True``. """ #Get dataset global gca #Add data series label = kwargs.pop('label', 'S_0') dn = len(x) xdata = plotutil.getplotdata(x) if isinstance(y1, (int, long, float)): yy = [] for i in range(dn): yy.append(y1) y1 = minum.array(yy).array else: y1 = plotutil.getplotdata(y1) if isinstance(y2, (int, long, float)): yy = [] for i in range(dn): yy.append(y2) y2 = minum.array(yy).array else: y2 = plotutil.getplotdata(y2) if not where is None: if isinstance(where, (tuple, list)): where = minum.array(where) where = where.asarray() #Set plot data styles if not 'fill' in kwargs: kwargs['fill'] = True if not 'edge' in kwargs: kwargs['edge'] = False pb, isunique = plotutil.getlegendbreak('polygon', **kwargs) pb.setCaption(label) #Create graphics offset = kwargs.pop('offset', 0) zdir = kwargs.pop('zdir', 'z') if zdir == 'xy': y = kwargs.pop('y', x) ydata = plotutil.getplotdata(y) graphics = GraphicFactory.createFillBetweenPolygons(xdata, ydata, y1, y2, where, pb, \ offset, zdir) else: graphics = GraphicFactory.createFillBetweenPolygons(xdata, y1, y2, where, pb, \ offset, zdir) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def plot_wireframe(self, *args, **kwargs): ''' creates a three-dimensional wireframe plot :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) 2-D z value array. :param cmap: (*string*) Color map string. :param xyaxis: (*boolean*) Draw x and y axis or not. :param zaxis: (*boolean*) Draw z axis or not. :param grid: (*boolean*) Draw grid or not. :param boxed: (*boolean*) Draw boxed or not. :param mesh: (*boolean*) Draw mesh line or not. :returns: Legend ''' if len(args) == 1: x = args[0].dimvalue(1) y = args[0].dimvalue(0) x, y = np.meshgrid(x, y) z = args[0] args = args[1:] else: x = args[0] y = args[1] z = args[2] args = args[3:] zcolors = kwargs.pop('zcolors', False) if not zcolors: line = plotutil.getlegendbreak('line', **kwargs)[0] graphics = GraphicFactory.createWireframe(x.asarray(), y.asarray(), z.asarray(), line) else: cmap = plotutil.getcolormap(**kwargs) if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createLegendScheme( z.min(), z.max(), cn, cmap) else: if isinstance(level_arg, NDArray): level_arg = level_arg.aslist() ls = LegendManage.createLegendScheme( z.min(), z.max(), level_arg, cmap) else: ls = LegendManage.createLegendScheme(z.min(), z.max(), cmap) ls = ls.convertTo(ShapeTypes.Polyline) plotutil.setlegendscheme(ls, **kwargs) graphics = GraphicFactory.createWireframe(x.asarray(), y.asarray(), z.asarray(), ls) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def plot_layer(self, layer, **kwargs): ''' Plot a layer in 3D axes. :param layer: (*MILayer*) The layer to be plotted. :returns: Graphics. ''' ls = kwargs.pop('symbolspec', None) layer = layer.layer if ls is None: ls = layer.getLegendScheme() if len(kwargs) > 0 and layer.getLegendScheme().getBreakNum() == 1: lb = layer.getLegendScheme().getLegendBreaks().get(0) btype = lb.getBreakType() geometry = 'point' if btype == BreakTypes.PolylineBreak: geometry = 'line' elif btype == BreakTypes.PolygonBreak: geometry = 'polygon' lb, isunique = plotutil.getlegendbreak(geometry, **kwargs) ls.getLegendBreaks().set(0, lb) plotutil.setlegendscheme(ls, **kwargs) layer.setLegendScheme(ls) offset = kwargs.pop('offset', 0) xshift = kwargs.pop('xshift', 0) graphics = GraphicFactory.createGraphicsFromLayer(layer, offset, xshift) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) miplot.draw_if_interactive() return graphics
def plot_wireframe(self, *args, **kwargs): ''' creates a three-dimensional wireframe plot :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) 2-D z value array. :param cmap: (*string*) Color map string. :param xyaxis: (*boolean*) Draw x and y axis or not. :param zaxis: (*boolean*) Draw z axis or not. :param grid: (*boolean*) Draw grid or not. :param boxed: (*boolean*) Draw boxed or not. :param mesh: (*boolean*) Draw mesh line or not. :returns: Legend ''' if len(args) == 1: x = args[0].dimvalue(1) y = args[0].dimvalue(0) x, y = minum.meshgrid(x, y) z = args[0] args = args[1:] else: x = args[0] y = args[1] z = args[2] args = args[3:] line = plotutil.getlegendbreak('line', **kwargs)[0] graphics = GraphicFactory.createWireframe(x.asarray(), y.asarray(), z.asarray(), line) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def geoshow(self, layer, **kwargs): ''' Plot a layer in 3D axes. :param layer: (*MILayer*) The layer to be plotted. :returns: Graphics. ''' ls = kwargs.pop('symbolspec', None) offset = kwargs.pop('offset', 0) xshift = kwargs.pop('xshift', 0) if isinstance(layer, basestring): fn = layer if not fn.endswith('.shp'): fn = fn + '.shp' if not os.path.exists(fn): fn = os.path.join(migl.get_map_folder(), fn) if os.path.exists(fn): encoding = kwargs.pop('encoding', None) layer = migeo.shaperead(fn, encoding) else: raise IOError('File not exists: ' + fn) layer = layer.layer if layer.getLayerType() == LayerTypes.VectorLayer: if ls is None: ls = layer.getLegendScheme() if layer.getLegendScheme().getBreakNum() == 1: lb = layer.getLegendScheme().getLegendBreaks().get(0) btype = lb.getBreakType() geometry = 'point' if btype == BreakTypes.PolylineBreak: geometry = 'line' elif btype == BreakTypes.PolygonBreak: geometry = 'polygon' if not kwargs.has_key('facecolor'): kwargs['facecolor'] = None if not kwargs.has_key('edgecolor'): kwargs['edgecolor'] = 'k' lb, isunique = plotutil.getlegendbreak(geometry, **kwargs) ls.getLegendBreaks().set(0, lb) else: plotutil.setlegendscheme(ls, **kwargs) layer.setLegendScheme(ls) graphics = GraphicFactory.createGraphicsFromLayer( layer, offset, xshift) else: interpolation = kwargs.pop('interpolation', None) graphics = JOGLUtil.createTexture(self.figure.getGL2(), layer, offset, xshift, interpolation) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def plot_layer(self, layer, **kwargs): ''' Plot a layer in 3D axes. :param layer: (*MILayer*) The layer to be plotted. :returns: Graphics. ''' ls = kwargs.pop('symbolspec', None) offset = kwargs.pop('offset', 0) xshift = kwargs.pop('xshift', 0) layer = layer.layer if layer.getLayerType() == LayerTypes.VectorLayer: if ls is None: ls = layer.getLegendScheme() if len(kwargs) > 0 and layer.getLegendScheme().getBreakNum() == 1: lb = layer.getLegendScheme().getLegendBreaks().get(0) btype = lb.getBreakType() geometry = 'point' if btype == BreakTypes.PolylineBreak: geometry = 'line' elif btype == BreakTypes.PolygonBreak: geometry = 'polygon' lb, isunique = plotutil.getlegendbreak(geometry, **kwargs) ls.getLegendBreaks().set(0, lb) plotutil.setlegendscheme(ls, **kwargs) layer.setLegendScheme(ls) graphics = GraphicFactory.createGraphicsFromLayer(layer, offset, xshift) else: interpolation = kwargs.pop('interpolation', None) graphics = GraphicFactory.createImage(layer, offset, xshift, interpolation) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def plot_surface(self, *args, **kwargs): ''' creates a three-dimensional surface plot :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) 2-D z value array. :param cmap: (*string*) Color map string. :param xyaxis: (*boolean*) Draw x and y axis or not. :param zaxis: (*boolean*) Draw z axis or not. :param grid: (*boolean*) Draw grid or not. :param boxed: (*boolean*) Draw boxed or not. :param mesh: (*boolean*) Draw mesh line or not. :returns: Legend ''' if len(args) <= 2: x = args[0].dimvalue(1) y = args[0].dimvalue(0) x, y = minum.meshgrid(x, y) z = args[0] args = args[1:] else: x = args[0] y = args[1] z = args[2] args = args[3:] cmap = plotutil.getcolormap(**kwargs) if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createLegendScheme(z.min(), z.max(), cn, cmap) else: if isinstance(level_arg, MIArray): level_arg = level_arg.aslist() ls = LegendManage.createLegendScheme(z.min(), z.max(), level_arg, cmap) else: ls = LegendManage.createLegendScheme(z.min(), z.max(), cmap) ls = ls.convertTo(ShapeTypes.Polygon) edge = kwargs.pop('edge', True) kwargs['edge'] = edge plotutil.setlegendscheme(ls, **kwargs) graphics = GraphicFactory.createMeshPolygons(x.asarray(), y.asarray(), z.asarray(), ls) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) miplot.draw_if_interactive() return graphics
def plot_surface(self, *args, **kwargs): ''' creates a three-dimensional surface plot :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) 2-D z value array. :param cmap: (*string*) Color map string. :param xyaxis: (*boolean*) Draw x and y axis or not. :param zaxis: (*boolean*) Draw z axis or not. :param grid: (*boolean*) Draw grid or not. :param boxed: (*boolean*) Draw boxed or not. :param mesh: (*boolean*) Draw mesh line or not. :returns: Legend ''' if len(args) <= 2: x = args[0].dimvalue(1) y = args[0].dimvalue(0) x, y = minum.meshgrid(x, y) z = args[0] args = args[1:] else: x = args[0] y = args[1] z = args[2] args = args[3:] cmap = plotutil.getcolormap(**kwargs) if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createLegendScheme(z.min(), z.max(), cn, cmap) else: if isinstance(level_arg, MIArray): level_arg = level_arg.aslist() ls = LegendManage.createLegendScheme(z.min(), z.max(), level_arg, cmap) else: ls = LegendManage.createLegendScheme(z.min(), z.max(), cmap) ls = ls.convertTo(ShapeTypes.Polygon) edge = kwargs.pop('edge', True) kwargs['edge'] = edge plotutil.setlegendscheme(ls, **kwargs) graphics = GraphicFactory.createMeshPolygons(x.asarray(), y.asarray(), z.asarray(), ls) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def geoshow(self, layer, **kwargs): ''' Plot a layer in 3D axes. :param layer: (*MILayer*) The layer to be plotted. :returns: Graphics. ''' ls = kwargs.pop('symbolspec', None) offset = kwargs.pop('offset', 0) xshift = kwargs.pop('xshift', 0) layer = layer.layer if layer.getLayerType() == LayerTypes.VectorLayer: if ls is None: ls = layer.getLegendScheme() if len(kwargs) > 0 and layer.getLegendScheme().getBreakNum( ) == 1: lb = layer.getLegendScheme().getLegendBreaks().get(0) btype = lb.getBreakType() geometry = 'point' if btype == BreakTypes.PolylineBreak: geometry = 'line' elif btype == BreakTypes.PolygonBreak: geometry = 'polygon' if not kwargs.has_key('facecolor'): kwargs['facecolor'] = None lb, isunique = plotutil.getlegendbreak(geometry, **kwargs) ls.getLegendBreaks().set(0, lb) plotutil.setlegendscheme(ls, **kwargs) layer.setLegendScheme(ls) graphics = GraphicFactory.createGraphicsFromLayer( layer, offset, xshift) else: interpolation = kwargs.pop('interpolation', None) graphics = JOGLUtil.createTexture(self.figure.getGL2(), layer, offset, xshift, interpolation) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def stem(self, x, y, z, s=8, c='b', marker='o', alpha=None, linewidth=None, verts=None, **kwargs): """ Make a 3D scatter plot of x, y and z, where x, y and z are sequence like objects of the same lengths. :param x: (*array_like*) Input x data. :param y: (*array_like*) Input y data. :param z: (*array_like*) Input z data. :param s: (*int*) Size of points. :param c: (*Color*) Color of the points. Or z vlaues. :param alpha: (*int*) The alpha blending value, between 0 (transparent) and 1 (opaque). :param marker: (*string*) Marker of the points. :param label: (*string*) Label of the points series. :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level points to draw, in increasing order. :returns: Points legend break. """ #Add data series label = kwargs.pop('label', 'S_0') xdata = plotutil.getplotdata(x) ydata = plotutil.getplotdata(y) zdata = plotutil.getplotdata(z) #Set plot data styles pb, isunique = plotutil.getlegendbreak('point', **kwargs) pb.setCaption(label) pstyle = plotutil.getpointstyle(marker) pb.setStyle(pstyle) bottom = kwargs.pop('bottom', 0) samestemcolor = kwargs.pop('samestemcolor', False) isvalue = False if len(c) > 1: if isinstance(c, (NDArray, DimArray)): isvalue = True elif isinstance(c[0], (int, long, float)): isvalue = True if isvalue: ls = kwargs.pop('symbolspec', None) if ls is None: if isinstance(c, (list, tuple)): c = np.array(c) levels = kwargs.pop('levs', None) if levels is None: levels = kwargs.pop('levels', None) if levels is None: cnum = kwargs.pop('cnum', None) if cnum is None: ls = plotutil.getlegendscheme([], c.min(), c.max(), **kwargs) else: ls = plotutil.getlegendscheme([cnum], c.min(), c.max(), **kwargs) else: ls = plotutil.getlegendscheme([levels], c.min(), c.max(), **kwargs) ls = plotutil.setlegendscheme_point(ls, **kwargs) if isinstance(s, int): for lb in ls.getLegendBreaks(): lb.setSize(s) else: n = len(s) for i in range(0, n): ls.getLegendBreaks()[i].setSize(s[i]) linefmt = kwargs.pop('linefmt', None) if linefmt is None: linefmt = PolylineBreak() linefmt.setColor(Color.black) else: linefmt = plotutil.getlegendbreak('line', **linefmt)[0] #Create graphics graphics = GraphicFactory.createStems3D(xdata, ydata, zdata, c.asarray(), \ ls, linefmt, bottom, samestemcolor) else: colors = plotutil.getcolors(c, alpha) pbs = [] if isinstance(s, int): pb.setSize(s) if len(colors) == 1: pb.setColor(colors[0]) pb.setOutlineColor(colors[0]) pbs.append(pb) else: n = len(colors) for i in range(0, n): npb = pb.clone() npb.setColor(colors[i]) npb.setOutlineColor(colors[i]) pbs.append(npb) else: n = len(s) if len(colors) == 1: pb.setColor(colors[0]) pb.setOutlineColor(colors[0]) for i in range(0, n): npb = pb.clone() npb.setSize(s[i]) pbs.append(npb) else: for i in range(0, n): npb = pb.clone() npb.setSize(s[i]) npb.setColor(colors[i]) npb.setOutlineColor(colors[i]) pbs.append(npb) linefmt = kwargs.pop('linefmt', None) if linefmt is None: linefmt = PolylineBreak() linefmt.setColor(colors[0]) else: linefmt = plotutil.getlegendbreak('line', **linefmt)[0] #Create graphics graphics = GraphicFactory.createStems3D(xdata, ydata, zdata, pbs, linefmt, \ bottom, samestemcolor) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics[0]) self.add_graphic(graphics[1]) return graphics[0], graphics[1]
def imshow(self, *args, **kwargs): """ Display an image on the 3D axes. :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) 2-D or 3-D (RGB) z value array. :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level curves to draw, in increasing order. :param cmap: (*string*) Color map string. :param colors: (*list*) If None (default), the colormap specified by cmap will be used. If a string, like ‘r’ or ‘red’, all levels will be plotted in this color. If a tuple of matplotlib color args (string, float, rgb, etc), different levels will be plotted in different colors in the order specified. :returns: (*RasterLayer*) RasterLayer created from array data. """ n = len(args) cmap = plotutil.getcolormap(**kwargs) fill_value = kwargs.pop('fill_value', -9999.0) xaxistype = None isrgb = False if n <= 2: if isinstance(args[0], (list, tuple)): isrgb = True rgbdata = args[0] if isinstance(rgbdata[0], MIArray): x = minum.arange(0, rgbdata[0].shape[1]) y = minum.arange(0, rgbdata[0].shape[0]) else: x = rgbdata[0].dimvalue(1) y = rgbdata[0].dimvalue(0) elif args[0].ndim > 2: isrgb = True rgbdata = args[0] if isinstance(rgbdata, MIArray): x = minum.arange(0, rgbdata.shape[1]) y = minum.arange(0, rgbdata.shape[0]) else: x = rgbdata.dimvalue(1) y = rgbdata.dimvalue(0) else: gdata = minum.asgridarray(args[0]) if isinstance(args[0], DimArray): if args[0].islondim(1): xaxistype = 'lon' elif args[0].islatdim(1): xaxistype = 'lat' elif args[0].istimedim(1): xaxistype = 'time' args = args[1:] elif n <=4: x = args[0] y = args[1] a = args[2] if isinstance(a, (list, tuple)): isrgb = True rgbdata = a elif a.ndim > 2: isrgb = True rgbdata = a else: gdata = minum.asgridarray(a, x, y, fill_value) args = args[3:] offset = kwargs.pop('offset', 0) zdir = kwargs.pop('zdir', 'z') interpolation = kwargs.pop('interpolation', None) if isrgb: if isinstance(rgbdata, (list, tuple)): rgbd = [] for d in rgbdata: rgbd.append(d.asarray()) rgbdata = rgbd else: rgbdata = rgbdata.asarray() x = plotutil.getplotdata(x) y = plotutil.getplotdata(y) graphics = GraphicFactory.createImage(x, y, rgbdata, offset, zdir, interpolation) ls = None else: if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createImageLegend(gdata, cn, cmap) else: if isinstance(level_arg, MIArray): level_arg = level_arg.aslist() ls = LegendManage.createImageLegend(gdata, level_arg, cmap) else: ls = plotutil.getlegendscheme(args, gdata.min(), gdata.max(), **kwargs) ls = ls.convertTo(ShapeTypes.Image) plotutil.setlegendscheme(ls, **kwargs) if zdir == 'xy': sepoint = kwargs.pop('sepoint', [0,0,1,1]) else: sepoint = None graphics = GraphicFactory.createImage(gdata, ls, offset, zdir, sepoint, interpolation) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def plot(self, x, y, z, *args, **kwargs): """ Plot 3D lines and/or markers to the axes. *args* is a variable length argument, allowing for multiple *x, y* pairs with an optional format string. :param x: (*array_like*) Input x data. :param y: (*array_like*) Input y data. :param z: (*array_like*) Input z data. :param style: (*string*) Line style for plot. :returns: Legend breaks of the lines. The following format string characters are accepted to control the line style or marker: ========= =========== Character Description ========= =========== '-' solid line style '--' dashed line style '-.' dash-dot line style ':' dotted line style '.' point marker ',' pixel marker 'o' circle marker 'v' triangle_down marker '^' triangle_up marker '<' triangle_left marker '>' triangle_right marker 's' square marker 'p' pentagon marker '*' star marker 'x' x marker 'D' diamond marker ========= =========== The following color abbreviations are supported: ========= ===== Character Color ========= ===== 'b' blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' black ========= ===== """ xdata = plotutil.getplotdata(x) ydata = plotutil.getplotdata(y) zdata = plotutil.getplotdata(z) style = None if len(args) > 0: style = args[0] #Set plot data styles label = kwargs.pop('label', 'S_1') mvalues = kwargs.pop('mvalues', None) if mvalues is None: if style is None: line = plotutil.getlegendbreak('line', **kwargs)[0] line.setCaption(label) else: line = plotutil.getplotstyle(style, label, **kwargs) colors = kwargs.pop('colors', None) if not colors is None: colors = plotutil.getcolors(colors) cbs = [] for color in colors: cb = line.clone() cb.setColor(color) cbs.append(cb) else: ls = kwargs.pop('symbolspec', None) if ls is None: if isinstance(mvalues, (list, tuple)): mvalues = minum.array(mvalues) levels = kwargs.pop('levs', None) if levels is None: levels = kwargs.pop('levels', None) if levels is None: cnum = kwargs.pop('cnum', None) if cnum is None: ls = plotutil.getlegendscheme([], mvalues.min(), mvalues.max(), **kwargs) else: ls = plotutil.getlegendscheme([cnum], mvalues.min(), mvalues.max(), **kwargs) else: ls = plotutil.getlegendscheme([levels], mvalues.min(), mvalues.max(), **kwargs) ls = plotutil.setlegendscheme_line(ls, **kwargs) #Add graphics if mvalues is None: if colors is None: graphics = GraphicFactory.createLineString3D(xdata, ydata, zdata, line) else: graphics = GraphicFactory.createLineString3D(xdata, ydata, zdata, cbs) else: mdata = plotutil.getplotdata(mvalues) graphics = GraphicFactory.createLineString3D(xdata, ydata, zdata, mdata, ls) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def plot(self, x, y, z, *args, **kwargs): """ Plot 3D lines and/or markers to the axes. *args* is a variable length argument, allowing for multiple *x, y* pairs with an optional format string. :param x: (*array_like*) Input x data. :param y: (*array_like*) Input y data. :param z: (*array_like*) Input z data. :param style: (*string*) Line style for plot. :returns: Legend breaks of the lines. The following format string characters are accepted to control the line style or marker: ========= =========== Character Description ========= =========== '-' solid line style '--' dashed line style '-.' dash-dot line style ':' dotted line style '.' point marker ',' pixel marker 'o' circle marker 'v' triangle_down marker '^' triangle_up marker '<' triangle_left marker '>' triangle_right marker 's' square marker 'p' pentagon marker '*' star marker 'x' x marker 'D' diamond marker ========= =========== The following color abbreviations are supported: ========= ===== Character Color ========= ===== 'b' blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' black ========= ===== """ xdata = plotutil.getplotdata(x) ydata = plotutil.getplotdata(y) zdata = plotutil.getplotdata(z) style = None if len(args) > 0: style = args[0] #Set plot data styles label = kwargs.pop('label', 'S_1') mvalues = kwargs.pop('mvalues', None) if mvalues is None: if style is None: line = plotutil.getlegendbreak('line', **kwargs)[0] line.setCaption(label) else: line = plotutil.getplotstyle(style, label, **kwargs) colors = kwargs.pop('colors', None) if not colors is None: colors = plotutil.getcolors(colors) cbs = [] for color in colors: cb = line.clone() cb.setColor(color) cbs.append(cb) else: ls = kwargs.pop('symbolspec', None) if ls is None: if isinstance(mvalues, (list, tuple)): mvalues = np.array(mvalues) levels = kwargs.pop('levs', None) if levels is None: levels = kwargs.pop('levels', None) if levels is None: cnum = kwargs.pop('cnum', None) if cnum is None: ls = plotutil.getlegendscheme([], mvalues.min(), mvalues.max(), **kwargs) else: ls = plotutil.getlegendscheme([cnum], mvalues.min(), mvalues.max(), **kwargs) else: ls = plotutil.getlegendscheme([levels], mvalues.min(), mvalues.max(), **kwargs) ls = plotutil.setlegendscheme_line(ls, **kwargs) #Add graphics if mvalues is None: if colors is None: graphics = GraphicFactory.createLineString3D( xdata, ydata, zdata, line) else: graphics = GraphicFactory.createLineString3D( xdata, ydata, zdata, cbs) else: mdata = plotutil.getplotdata(mvalues) graphics = GraphicFactory.createLineString3D( xdata, ydata, zdata, mdata, ls) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def quiver(self, *args, **kwargs): """ Plot a 2-D field of arrows. :param x: (*array_like*) X coordinate array. :param y: (*array_like*) Y coordinate array. :param z: (*array_like*) Z coordinate array. :param u: (*array_like*) U component of the arrow vectors (wind field). :param v: (*array_like*) V component of the arrow vectors (wind field). :param w: (*array_like*) W component of the arrow vectors (wind field). :param z: (*array_like*) Optional, 2-D z value array. :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level vectors to draw, in increasing order. :param cmap: (*string*) Color map string. :param fill_value: (*float*) Fill_value. Default is ``-9999.0``. :param length: (*float*) The length of each quiver, default to 1.0, the unit is the same with the axes. :returns: (*Graphic list*) Created quiver graphics. """ ls = kwargs.pop('symbolspec', None) cmap = plotutil.getcolormap(**kwargs) fill_value = kwargs.pop('fill_value', -9999.0) n = len(args) iscolor = False cdata = None xaxistype = None x = args[0] y = args[1] z = args[2] u = args[3] v = args[4] w = args[5] args = args[6:] if len(args) > 0: cdata = args[0] iscolor = True args = args[1:] x = plotutil.getplotdata(x) y = plotutil.getplotdata(y) z = plotutil.getplotdata(z) u = plotutil.getplotdata(u) v = plotutil.getplotdata(v) w = plotutil.getplotdata(w) if ls is None: if iscolor: if len(args) > 0: cn = args[0] ls = LegendManage.createLegendScheme( cdata.min(), cdata.max(), cn, cmap) else: levs = kwargs.pop('levs', None) if levs is None: ls = LegendManage.createLegendScheme( cdata.min(), cdata.max(), cmap) else: if isinstance(levs, NDArray): levs = levs.tolist() ls = LegendManage.createLegendScheme( cdata.min(), cdata.max(), levs, cmap) else: if cmap.getColorCount() == 1: c = cmap.getColor(0) else: c = Color.black ls = LegendManage.createSingleSymbolLegendScheme( ShapeTypes.Point, c, 10) ls = plotutil.setlegendscheme_point(ls, **kwargs) if not cdata is None: cdata = plotutil.getplotdata(cdata) length = kwargs.pop('length', 1) igraphic = GraphicFactory.createArrows3D(x, y, z, u, v, w, length, cdata, ls) visible = kwargs.pop('visible', True) if visible: self.add_graphic(igraphic) return igraphic
def stem(self, x, y, z, s=8, c='b', marker='o', alpha=None, linewidth=None, verts=None, **kwargs): """ Make a 3D scatter plot of x, y and z, where x, y and z are sequence like objects of the same lengths. :param x: (*array_like*) Input x data. :param y: (*array_like*) Input y data. :param z: (*array_like*) Input z data. :param s: (*int*) Size of points. :param c: (*Color*) Color of the points. Or z vlaues. :param alpha: (*int*) The alpha blending value, between 0 (transparent) and 1 (opaque). :param marker: (*string*) Marker of the points. :param label: (*string*) Label of the points series. :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level points to draw, in increasing order. :returns: Points legend break. """ #Add data series label = kwargs.pop('label', 'S_0') xdata = plotutil.getplotdata(x) ydata = plotutil.getplotdata(y) zdata = plotutil.getplotdata(z) #Set plot data styles pb, isunique = plotutil.getlegendbreak('point', **kwargs) pb.setCaption(label) pstyle = plotutil.getpointstyle(marker) pb.setStyle(pstyle) bottom = kwargs.pop('bottom', 0) samestemcolor = kwargs.pop('samestemcolor', False) isvalue = False if len(c) > 1: if isinstance(c, (MIArray, DimArray)): isvalue = True elif isinstance(c[0], (int, long, float)): isvalue = True if isvalue: ls = kwargs.pop('symbolspec', None) if ls is None: if isinstance(c, (list, tuple)): c = minum.array(c) levels = kwargs.pop('levs', None) if levels is None: levels = kwargs.pop('levels', None) if levels is None: cnum = kwargs.pop('cnum', None) if cnum is None: ls = plotutil.getlegendscheme([], c.min(), c.max(), **kwargs) else: ls = plotutil.getlegendscheme([cnum], c.min(), c.max(), **kwargs) else: ls = plotutil.getlegendscheme([levels], c.min(), c.max(), **kwargs) ls = plotutil.setlegendscheme_point(ls, **kwargs) if isinstance(s, int): for lb in ls.getLegendBreaks(): lb.setSize(s) else: n = len(s) for i in range(0, n): ls.getLegendBreaks()[i].setSize(s[i]) linefmt = kwargs.pop('linefmt', None) if linefmt is None: linefmt = PolylineBreak() linefmt.setColor(Color.black) else: linefmt = plotutil.getlegendbreak('line', **linefmt)[0] #Create graphics graphics = GraphicFactory.createStems3D(xdata, ydata, zdata, c.asarray(), \ ls, linefmt, bottom, samestemcolor) else: colors = plotutil.getcolors(c, alpha) pbs = [] if isinstance(s, int): pb.setSize(s) if len(colors) == 1: pb.setColor(colors[0]) pb.setOutlineColor(colors[0]) pbs.append(pb) else: n = len(colors) for i in range(0, n): npb = pb.clone() npb.setColor(colors[i]) npb.setOutlineColor(colors[i]) pbs.append(npb) else: n = len(s) if len(colors) == 1: pb.setColor(colors[0]) pb.setOutlineColor(colors[0]) for i in range(0, n): npb = pb.clone() npb.setSize(s[i]) pbs.append(npb) else: for i in range(0, n): npb = pb.clone() npb.setSize(s[i]) npb.setColor(colors[i]) npb.setOutlineColor(colors[i]) pbs.append(npb) linefmt = kwargs.pop('linefmt', None) if linefmt is None: linefmt = PolylineBreak() linefmt.setColor(colors[0]) else: linefmt = plotutil.getlegendbreak('line', **linefmt)[0] #Create graphics graphics = GraphicFactory.createStems3D(xdata, ydata, zdata, pbs, linefmt, \ bottom, samestemcolor) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics[0]) self.add_graphic(graphics[1]) return graphics[0], graphics[1]
def contourf(self, *args, **kwargs): """ Plot filled contours. :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) 2-D z value array. :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level curves to draw, in increasing order. :param cmap: (*string*) Color map string. :param colors: (*list*) If None (default), the colormap specified by cmap will be used. If a string, like ‘r’ or ‘red’, all levels will be plotted in this color. If a tuple of matplotlib color args (string, float, rgb, etc), different levels will be plotted in different colors in the order specified. :param smooth: (*boolean*) Smooth countour lines or not. :returns: (*VectoryLayer*) Contour VectoryLayer created from array data. """ n = len(args) cmap = plotutil.getcolormap(**kwargs) fill_value = kwargs.pop('fill_value', -9999.0) offset = kwargs.pop('offset', 0) xaxistype = None if n <= 2: gdata = minum.asgriddata(args[0]) if isinstance(args[0], DimArray): if args[0].islondim(1): xaxistype = 'lon' elif args[0].islatdim(1): xaxistype = 'lat' elif args[0].istimedim(1): xaxistype = 'time' args = args[1:] elif n <=4: x = args[0] y = args[1] a = args[2] gdata = minum.asgriddata(a, x, y, fill_value) args = args[3:] if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createLegendScheme(gdata.min(), gdata.max(), cn, cmap) else: if isinstance(level_arg, MIArray): level_arg = level_arg.aslist() ls = LegendManage.createLegendScheme(gdata.min(), gdata.max(), level_arg, cmap) else: ls = LegendManage.createLegendScheme(gdata.min(), gdata.max(), cmap) ls = ls.convertTo(ShapeTypes.Polygon) edge = kwargs.pop('edge', None) if edge is None: kwargs['edge'] = False else: kwargs['edge'] = edge plotutil.setlegendscheme(ls, **kwargs) smooth = kwargs.pop('smooth', True) zdir = kwargs.pop('zdir', 'z') if zdir == 'xy': sepoint = kwargs.pop('sepoint', [0,0,1,1]) igraphic = GraphicFactory.createContourPolygons(gdata.data, offset, zdir, ls, smooth, \ sepoint) else: igraphic = GraphicFactory.createContourPolygons(gdata.data, offset, zdir, ls, smooth) visible = kwargs.pop('visible', True) if visible: self.add_graphic(igraphic) return igraphic
def contourf(self, *args, **kwargs): """ Plot filled contours. :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) 2-D z value array. :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level curves to draw, in increasing order. :param cmap: (*string*) Color map string. :param colors: (*list*) If None (default), the colormap specified by cmap will be used. If a string, like ‘r’ or ‘red’, all levels will be plotted in this color. If a tuple of matplotlib color args (string, float, rgb, etc), different levels will be plotted in different colors in the order specified. :param smooth: (*boolean*) Smooth countour lines or not. :returns: (*VectoryLayer*) Contour VectoryLayer created from array data. """ n = len(args) cmap = plotutil.getcolormap(**kwargs) fill_value = kwargs.pop('fill_value', -9999.0) offset = kwargs.pop('offset', 0) xaxistype = None if n <= 2: gdata = np.asgriddata(args[0]) if isinstance(args[0], DimArray): if args[0].islondim(1): xaxistype = 'lon' elif args[0].islatdim(1): xaxistype = 'lat' elif args[0].istimedim(1): xaxistype = 'time' args = args[1:] elif n <= 4: x = args[0] y = args[1] a = args[2] gdata = np.asgriddata(a, x, y, fill_value) args = args[3:] if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createLegendScheme(gdata.min(), gdata.max(), cn, cmap) else: if isinstance(level_arg, NDArray): level_arg = level_arg.aslist() ls = LegendManage.createLegendScheme(gdata.min(), gdata.max(), level_arg, cmap) else: ls = LegendManage.createLegendScheme(gdata.min(), gdata.max(), cmap) ls = ls.convertTo(ShapeTypes.Polygon) edge = kwargs.pop('edge', None) if edge is None: kwargs['edge'] = False else: kwargs['edge'] = edge plotutil.setlegendscheme(ls, **kwargs) smooth = kwargs.pop('smooth', True) zdir = kwargs.pop('zdir', 'z') if zdir == 'xy': sepoint = kwargs.pop('sepoint', [0, 0, 1, 1]) igraphic = GraphicFactory.createContourPolygons(gdata.data, offset, zdir, ls, smooth, \ sepoint) else: igraphic = GraphicFactory.createContourPolygons( gdata.data, offset, zdir, ls, smooth) visible = kwargs.pop('visible', True) if visible: self.add_graphic(igraphic) return igraphic
def streamplot(self, *args, **kwargs): """ Plot stream lines in 3D axes. :param x: (*array_like*) X coordinate array. :param y: (*array_like*) Y coordinate array. :param z: (*array_like*) Z coordinate array. :param u: (*array_like*) U component of the arrow vectors (wind field). :param v: (*array_like*) V component of the arrow vectors (wind field). :param w: (*array_like*) W component of the arrow vectors (wind field). :param density: (*int*) Streamline density. Default is 4. :return: Streamlines """ ls = kwargs.pop('symbolspec', None) cmap = plotutil.getcolormap(**kwargs) density = kwargs.pop('density', 4) iscolor = False cdata = None if len(args) < 6: u = args[0] v = args[1] w = args[2] u = np.asarray(u) nz, ny, nx = u.shape x = np.arange(nx) y = np.arange(ny) z = np.arange(nz) args = args[3:] else: x = args[0] y = args[1] z = args[2] u = args[3] v = args[4] w = args[5] args = args[6:] if len(args) > 0: cdata = args[0] iscolor = True args = args[1:] x = plotutil.getplotdata(x) y = plotutil.getplotdata(y) z = plotutil.getplotdata(z) u = plotutil.getplotdata(u) v = plotutil.getplotdata(v) w = plotutil.getplotdata(w) if ls is None: if iscolor: if len(args) > 0: cn = args[0] ls = LegendManage.createLegendScheme( cdata.min(), cdata.max(), cn, cmap) else: levs = kwargs.pop('levs', None) if levs is None: ls = LegendManage.createLegendScheme( cdata.min(), cdata.max(), cmap) else: if isinstance(levs, NDArray): levs = levs.tolist() ls = LegendManage.createLegendScheme( cdata.min(), cdata.max(), levs, cmap) else: if cmap.getColorCount() == 1: c = cmap.getColor(0) else: c = Color.black ls = LegendManage.createSingleSymbolLegendScheme( ShapeTypes.Polyline, c, 1) ls = plotutil.setlegendscheme_line(ls, **kwargs) if not kwargs.has_key('headwidth'): kwargs['headwidth'] = 1 if not kwargs.has_key('headlength'): kwargs['headlength'] = 2.5 for i in range(ls.getBreakNum()): lb = plotutil.line2stream(ls.getLegendBreak(i), **kwargs) ls.setLegendBreak(i, lb) if not cdata is None: cdata = plotutil.getplotdata(cdata) min_points = kwargs.pop('min_points', 3) start_x = kwargs.pop('start_x', None) start_y = kwargs.pop('start_y', None) start_z = kwargs.pop('start_z', None) if start_x is None or start_y is None or start_z is None: graphics = GraphicFactory.createStreamlines3D( x, y, z, u, v, w, cdata, density, ls, min_points) else: start_x = np.asarray(start_x).flatten() start_y = np.asarray(start_y).flatten() start_z = np.asarray(start_z).flatten() graphics = GraphicFactory.createStreamlines3D( x, y, z, u, v, w, cdata, density, ls, min_points, start_x._array, start_y._array, start_z._array) lighting = kwargs.pop('lighting', None) if not lighting is None: graphics.setUsingLight(lighting) self.add_graphic(graphics) return graphics
def imshow(self, *args, **kwargs): """ Display an image on the 3D axes. :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) 2-D or 3-D (RGB) z value array. :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level curves to draw, in increasing order. :param cmap: (*string*) Color map string. :param colors: (*list*) If None (default), the colormap specified by cmap will be used. If a string, like ‘r’ or ‘red’, all levels will be plotted in this color. If a tuple of matplotlib color args (string, float, rgb, etc), different levels will be plotted in different colors in the order specified. :returns: (*RasterLayer*) RasterLayer created from array data. """ n = len(args) cmap = plotutil.getcolormap(**kwargs) fill_value = kwargs.pop('fill_value', -9999.0) xaxistype = None isrgb = False if n <= 2: if isinstance(args[0], (list, tuple)): isrgb = True rgbdata = args[0] if isinstance(rgbdata[0], NDArray): x = np.arange(0, rgbdata[0].shape[1]) y = np.arange(0, rgbdata[0].shape[0]) else: x = rgbdata[0].dimvalue(1) y = rgbdata[0].dimvalue(0) elif args[0].ndim > 2: isrgb = True rgbdata = args[0] if isinstance(rgbdata, NDArray): x = np.arange(0, rgbdata.shape[1]) y = np.arange(0, rgbdata.shape[0]) else: x = rgbdata.dimvalue(1) y = rgbdata.dimvalue(0) else: gdata = np.asgridarray(args[0]) if isinstance(args[0], DimArray): if args[0].islondim(1): xaxistype = 'lon' elif args[0].islatdim(1): xaxistype = 'lat' elif args[0].istimedim(1): xaxistype = 'time' args = args[1:] elif n <= 4: x = args[0] y = args[1] a = args[2] if isinstance(a, (list, tuple)): isrgb = True rgbdata = a elif a.ndim > 2: isrgb = True rgbdata = a else: gdata = np.asgridarray(a, x, y, fill_value) args = args[3:] offset = kwargs.pop('offset', 0) zdir = kwargs.pop('zdir', 'z') interpolation = kwargs.pop('interpolation', None) if isrgb: if isinstance(rgbdata, (list, tuple)): rgbd = [] for d in rgbdata: rgbd.append(d.asarray()) rgbdata = rgbd else: rgbdata = rgbdata.asarray() x = plotutil.getplotdata(x) y = plotutil.getplotdata(y) graphics = GraphicFactory.createImage(x, y, rgbdata, offset, zdir, interpolation) ls = None else: if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createImageLegend(gdata, cn, cmap) else: if isinstance(level_arg, NDArray): level_arg = level_arg.aslist() ls = LegendManage.createImageLegend(gdata, level_arg, cmap) else: ls = plotutil.getlegendscheme(args, gdata.min(), gdata.max(), **kwargs) ls = ls.convertTo(ShapeTypes.Image) plotutil.setlegendscheme(ls, **kwargs) if zdir == 'xy': sepoint = kwargs.pop('sepoint', [0, 0, 1, 1]) else: sepoint = None graphics = GraphicFactory.createImage(gdata, ls, offset, zdir, sepoint, interpolation) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def quiver(self, *args, **kwargs): """ Plot a 2-D field of arrows. :param x: (*array_like*) X coordinate array. :param y: (*array_like*) Y coordinate array. :param z: (*array_like*) Z coordinate array. :param u: (*array_like*) U component of the arrow vectors (wind field). :param v: (*array_like*) V component of the arrow vectors (wind field). :param w: (*array_like*) W component of the arrow vectors (wind field). :param z: (*array_like*) Optional, 2-D z value array. :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level vectors to draw, in increasing order. :param cmap: (*string*) Color map string. :param fill_value: (*float*) Fill_value. Default is ``-9999.0``. :param length: (*float*) The length of each quiver, default to 1.0, the unit is the same with the axes. :returns: (*Graphic list*) Created quiver graphics. """ ls = kwargs.pop('symbolspec', None) cmap = plotutil.getcolormap(**kwargs) fill_value = kwargs.pop('fill_value', -9999.0) n = len(args) iscolor = False cdata = None xaxistype = None x = args[0] y = args[1] z = args[2] u = args[3] v = args[4] w = args[5] args = args[6:] if len(args) > 0: cdata = args[0] iscolor = True args = args[1:] x = plotutil.getplotdata(x) y = plotutil.getplotdata(y) z = plotutil.getplotdata(z) u = plotutil.getplotdata(u) v = plotutil.getplotdata(v) w = plotutil.getplotdata(w) if ls is None: if iscolor: if len(args) > 0: cn = args[0] ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), cn, cmap) else: levs = kwargs.pop('levs', None) if levs is None: ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), cmap) else: if isinstance(levs, MIArray): levs = levs.tolist() ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), levs, cmap) else: if cmap.getColorCount() == 1: c = cmap.getColor(0) else: c = Color.black ls = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Point, c, 10) ls = plotutil.setlegendscheme_point(ls, **kwargs) if not cdata is None: cdata = plotutil.getplotdata(cdata) length = kwargs.pop('length', 1) igraphic = GraphicFactory.createArrows3D(x, y, z, u, v, w, length, cdata, ls) visible = kwargs.pop('visible', True) if visible: self.add_graphic(igraphic) return igraphic
def streamslice(self, *args, **kwargs): """ Plot stream lines slice in 3D axes. :param x: (*array_like*) X coordinate array. :param y: (*array_like*) Y coordinate array. :param z: (*array_like*) Z coordinate array. :param u: (*array_like*) U component of the arrow vectors (wind field). :param v: (*array_like*) V component of the arrow vectors (wind field). :param w: (*array_like*) W component of the arrow vectors (wind field). :param xslice: (*list*) X slice locations. :param yslice: (*list*) Y slice locations. :param zslice: (*list*) Z slice locations. :param density: (*int*) Streamline density. Default is 4. :return: Streamline slices """ ls = kwargs.pop('symbolspec', None) cmap = plotutil.getcolormap(**kwargs) density = kwargs.pop('density', 4) iscolor = False cdata = None if len(args) < 6: u = args[0] v = args[1] w = args[2] u = np.asarray(u) nz, ny, nx = u.shape x = np.arange(nx) y = np.arange(ny) z = np.arange(nz) args = args[3:] else: x = args[0] y = args[1] z = args[2] u = args[3] v = args[4] w = args[5] args = args[6:] if len(args) > 0: cdata = args[0] iscolor = True args = args[1:] x = plotutil.getplotdata(x) y = plotutil.getplotdata(y) z = plotutil.getplotdata(z) u = plotutil.getplotdata(u) v = plotutil.getplotdata(v) w = plotutil.getplotdata(w) if ls is None: if iscolor: if len(args) > 0: cn = args[0] ls = LegendManage.createLegendScheme( cdata.min(), cdata.max(), cn, cmap) else: levs = kwargs.pop('levs', None) if levs is None: ls = LegendManage.createLegendScheme( cdata.min(), cdata.max(), cmap) else: if isinstance(levs, NDArray): levs = levs.tolist() ls = LegendManage.createLegendScheme( cdata.min(), cdata.max(), levs, cmap) else: if cmap.getColorCount() == 1: c = cmap.getColor(0) else: c = Color.black ls = LegendManage.createSingleSymbolLegendScheme( ShapeTypes.Polyline, c, 1) ls = plotutil.setlegendscheme_line(ls, **kwargs) if not kwargs.has_key('headwidth'): kwargs['headwidth'] = 1 if not kwargs.has_key('headlength'): kwargs['headlength'] = 2.5 for i in range(ls.getBreakNum()): lb = plotutil.line2stream(ls.getLegendBreak(i), **kwargs) ls.setLegendBreak(i, lb) if not cdata is None: cdata = plotutil.getplotdata(cdata) min_points = kwargs.pop('min_points', 3) zslice_index = kwargs.pop('zslice_index', None) if zslice_index is None: xslice = kwargs.pop('xslice', []) if isinstance(xslice, numbers.Number): xslice = [xslice] yslice = kwargs.pop('yslice', []) if isinstance(yslice, numbers.Number): yslice = [yslice] zslice = kwargs.pop('zslice', []) if isinstance(zslice, numbers.Number): zslice = [zslice] graphics = GraphicFactory.streamSlice(x, y, z, u, v, w, cdata, xslice, yslice, zslice, density, ls) else: if isinstance(zslice_index, int): zslice_index = [zslice_index] graphics = GraphicFactory.streamSlice(x, y, z, u, v, w, cdata, zslice_index, density, ls) lighting = kwargs.pop('lighting', None) if not lighting is None: for gg in graphics: gg.setUsingLight(lighting) visible = kwargs.pop('visible', True) if visible: for gg in graphics: self.add_graphic(gg) return graphics
def imshow(self, *args, **kwargs): """ Display an image on the map. :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) 2-D z value array. :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level curves to draw, in increasing order. :param cmap: (*string*) Color map string. :param colors: (*list*) If None (default), the colormap specified by cmap will be used. If a string, like ‘r’ or ‘red’, all levels will be plotted in this color. If a tuple of matplotlib color args (string, float, rgb, etc), different levels will be plotted in different colors in the order specified. :param fill_value: (*float*) Fill_value. Default is ``-9999.0``. :param fill_color: (*color*) Fill_color. Default is None (white color). :param proj: (*ProjectionInfo*) Map projection of the data. Default is None. :param zorder: (*int*) Z-order of created layer for display. :param interpolation: (*string*) Interpolation option [None | bilinear | bicubic]. :returns: (*RasterLayer*) RasterLayer created from array data. """ cmap = plotutil.getcolormap(**kwargs) fill_value = kwargs.pop('fill_value', -9999.0) ls = kwargs.pop('symbolspec', None) n = len(args) isrgb = False if n <= 2: if isinstance(args[0], (list, tuple)): isrgb = True rgbdata = args[0] if isinstance(rgbdata[0], DimArray): x = rgbdata[0].dimvalue(1) y = rgbdata[0].dimvalue(0) else: x = minum.arange(0, rgbdata[0].shape[1]) y = minum.arange(0, rgbdata[0].shape[0]) elif args[0].ndim > 2: isrgb = True rgbdata = args[0] x = rgbdata.dimvalue(1) y = rgbdata.dimvalue(0) else: gdata = minum.asgridarray(args[0]) args = args[1:] elif n <=4: x = args[0] y = args[1] a = args[2] if isinstance(a, (list, tuple)): isrgb = True rgbdata = a elif a.ndim > 2: isrgb = True rgbdata = a else: gdata = minum.asgridarray(a, x, y, fill_value) args = args[3:] isadd = kwargs.pop('isadd', True) interpolation = kwargs.pop('interpolation', None) if isrgb: if isinstance(rgbdata, (list, tuple)): rgbd = [] for d in rgbdata: rgbd.append(d.asarray()) rgbdata = rgbd else: rgbdata = rgbdata.asarray() extent = [x[0],x[-1],y[0],y[-1]] igraphic = GraphicFactory.createImage(rgbdata, extent) x = plotutil.getplotdata(x) y = plotutil.getplotdata(y) layer = DrawMeteoData.createImageLayer(x, y, igraphic, 'layer_image') else: if len(args) > 0: if ls is None: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createImageLegend(gdata, cn, cmap) else: if isinstance(level_arg, MIArray): level_arg = level_arg.aslist() ls = LegendManage.createImageLegend(gdata, level_arg, cmap) else: if ls is None: ls = LegendManage.createImageLegend(gdata, cmap) plotutil.setlegendscheme(ls, **kwargs) fill_color = kwargs.pop('fill_color', None) if not fill_color is None: cb = ls.getLegendBreaks().get(ls.getBreakNum() - 1) if cb.isNoData(): cb.setColor(plotutil.getcolor(fill_color)) layer = DrawMeteoData.createRasterLayer(gdata, 'layer', ls) proj = kwargs.pop('proj', None) if not proj is None: layer.setProjInfo(proj) if not interpolation is None: layer.setInterpolation(interpolation) if isadd: zorder = kwargs.pop('zorder', None) select = kwargs.pop('select', True) if zorder is None: zorder = 0 self.add_layer(layer, zorder, select) self.axes.setDrawExtent(layer.getExtent().clone()) self.axes.setExtent(layer.getExtent().clone()) return MILayer(layer)
def bar(self, x, y, z, width=0.8, bottom=None, cylinder=False, **kwargs): """ Make a 3D bar plot of x, y and z, where x, y and z are sequence like objects of the same lengths. :param x: (*array_like*) Input x data. :param y: (*array_like*) Input y data. :param z: (*array_like*) Input z data. :param width: (*float*) Bar width. :param cylinder: (*bool*) Is sylinder bar or rectangle bar. :param bottom: (*bool*) Color of the points. Or z vlaues. :param color: (*Color*) Optional, the color of the bar faces. :param edgecolor: (*Color*) Optional, the color of the bar edge. Default is black color. Edge line will not be plotted if ``edgecolor`` is ``None``. :param linewidth: (*int*) Optional, width of bar edge. :param label: (*string*) Label of the bar series. :param hatch: (*string*) Hatch string. :param hatchsize: (*int*) Hatch size. Default is None (8). :param bgcolor: (*Color*) Background color, only valid with hatch. :param barswidth: (*float*) Bars width (0 - 1), only used for automatic bar with plot (only one argument widthout ``width`` augument). Defaul is 0.8. :returns: Points legend break. """ #Add data series label = kwargs.pop('label', 'S_0') xdata = plotutil.getplotdata(x) ydata = plotutil.getplotdata(y) zdata = plotutil.getplotdata(z) autowidth = False width = np.asarray(width) if not bottom is None: bottom = plotutil.getplotdata(bottom) #Set plot data styles fcobj = kwargs.pop('color', None) if fcobj is None: fcobj = kwargs.pop('facecolor', 'b') if isinstance(fcobj, (tuple, list)): colors = plotutil.getcolors(fcobj) else: color = plotutil.getcolor(fcobj) colors = [color] ecobj = kwargs.pop('edgecolor', 'k') edgecolor = plotutil.getcolor(ecobj) linewidth = kwargs.pop('linewidth', 1.0) hatch = kwargs.pop('hatch', None) hatch = plotutil.gethatch(hatch) hatchsize = kwargs.pop('hatchsize', None) bgcolor = kwargs.pop('bgcolor', None) bgcolor = plotutil.getcolor(bgcolor) ecolor = kwargs.pop('ecolor', 'k') ecolor = plotutil.getcolor(ecolor) barbreaks = [] for color in colors: lb = BarBreak() lb.setCaption(label) lb.setColor(color) if edgecolor is None: lb.setDrawOutline(False) else: lb.setOutlineColor(edgecolor) lb.setOutlineSize(linewidth) if not hatch is None: lb.setStyle(hatch) if not bgcolor is None: lb.setBackColor(bgcolor) if not hatchsize is None: lb.setStyleSize(hatchsize) lb.setErrorColor(ecolor) barbreaks.append(lb) #Create bar graphics if isinstance(width, NDArray): width = width.asarray() if cylinder: graphics = GraphicFactory.createCylinderBars3D( xdata, ydata, zdata, autowidth, width, bottom, barbreaks) else: graphics = GraphicFactory.createBars3D(xdata, ydata, zdata, autowidth, width, bottom, barbreaks) self.add_graphic(graphics) return barbreaks
def plot(self, x, y, z, *args, **kwargs): """ Plot 3D lines and/or markers to the axes. *args* is a variable length argument, allowing for multiple *x, y* pairs with an optional format string. :param x: (*array_like*) Input x data. :param y: (*array_like*) Input y data. :param z: (*array_like*) Input z data. :param style: (*string*) Line style for plot. :returns: Legend breaks of the lines. The following format string characters are accepted to control the line style or marker: ========= =========== Character Description ========= =========== '-' solid line style '--' dashed line style '-.' dash-dot line style ':' dotted line style '.' point marker ',' pixel marker 'o' circle marker 'v' triangle_down marker '^' triangle_up marker '<' triangle_left marker '>' triangle_right marker 's' square marker 'p' pentagon marker '*' star marker 'x' x marker 'D' diamond marker ========= =========== The following color abbreviations are supported: ========= ===== Character Color ========= ===== 'b' blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' black ========= ===== """ xdata = plotutil.getplotdata(x) ydata = plotutil.getplotdata(y) zdata = plotutil.getplotdata(z) style = None if len(args) > 0: style = args[0] #Set plot data styles label = kwargs.pop('label', 'S_1') if style is None: line = plotutil.getlegendbreak('line', **kwargs)[0] line.setCaption(label) else: line = plotutil.getplotstyle(style, label, **kwargs) #Add graphics graphics = GraphicFactory.createLineString(xdata, ydata, zdata, line) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics