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_isosurface(self, *args, **kwargs): ''' creates a three-dimensional isosurface plot :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) Optional. Z coordinate array. :param data: (*array_like*) 3D data array. :param cmap: (*string*) Color map string. :param nthread: (*int*) Thread number. :returns: Legend ''' if len(args) <= 3: x = args[0].dimvalue(2) y = args[0].dimvalue(1) z = args[0].dimvalue(0) data = args[0] isovalue = args[1] args = args[2:] else: x = args[0] y = args[1] z = args[2] data = args[3] isovalue = args[4] args = args[5:] cmap = plotutil.getcolormap(**kwargs) cvalue = kwargs.pop('cvalue', None) if not cvalue is None: if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createLegendScheme(data.min(), data.max(), cn, cmap) else: if isinstance(level_arg, NDArray): level_arg = level_arg.aslist() ls = LegendManage.createLegendScheme(data.min(), data.max(), level_arg, cmap) else: ls = LegendManage.createLegendScheme(data.min(), data.max(), cmap) ls = ls.convertTo(ShapeTypes.Polygon) edge = kwargs.pop('edge', True) kwargs['edge'] = edge plotutil.setlegendscheme(ls, **kwargs) else: ls = plotutil.getlegendbreak('polygon', **kwargs)[0] nthread = kwargs.pop('nthread', None) if nthread is None: graphics = JOGLUtil.isosurface(data.asarray(), x.asarray(), y.asarray(), z.asarray(), isovalue, ls) else: graphics = JOGLUtil.isosurface(data.asarray(), x.asarray(), y.asarray(), z.asarray(), isovalue, ls, nthread) 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. :returns: Legend ''' if len(args) <= 2: 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:] if kwargs.has_key('colors'): cn = len(kwargs['colors']) else: cn = None 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: if cn is None: ls = LegendManage.createLegendScheme(z.min(), z.max(), cmap) else: ls = LegendManage.createLegendScheme(z.min(), z.max(), cn, cmap) ls = ls.convertTo(ShapeTypes.Polygon) edge = kwargs.pop('edge', True) kwargs['edge'] = edge plotutil.setlegendscheme(ls, **kwargs) graphics = JOGLUtil.surface(x.asarray(), y.asarray(), z.asarray(), ls) 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 stationmodel(self, smdata, **kwargs): """ Plot station model data on the map. :param smdata: (*StationModelData*) Station model data. :param surface: (*boolean*) Is surface data or not. Default is True. :param size: (*float*) Size of the station model symbols. Default is 12. :param proj: (*ProjectionInfo*) Map projection of the data. Default is None. :param order: (*int*) Z-order of created layer for display. :returns: (*VectoryLayer*) Station model VectoryLayer. """ proj = kwargs.pop('proj', None) size = kwargs.pop('size', 12) surface = kwargs.pop('surface', True) ls = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Point, Color.blue, size) layer = DrawMeteoData.createStationModelLayer(smdata, ls, 'stationmodel', surface) if (proj != None): layer.setProjInfo(proj) # Add layer isadd = kwargs.pop('isadd', True) if isadd: zorder = kwargs.pop('zorder', None) select = kwargs.pop('select', True) self.add_layer(layer, zorder, select) self.axes.setDrawExtent(layer.getExtent().clone()) self.axes.setExtent(layer.getExtent().clone()) return MILayer(layer)
def streamplot(self, *args, **kwargs): """ Plot streamline in a map. :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param u: (*array_like*) U component of the arrow vectors (wind field) or wind direction. :param v: (*array_like*) V component of the arrow vectors (wind field) or wind speed. :param z: (*array_like*) Optional, 2-D z value array. :param color: (*Color*) Streamline color. Default is blue. :param fill_value: (*float*) Fill_value. Default is ``-9999.0``. :param isuv: (*boolean*) Is U/V or direction/speed data array pairs. Default is True. :param density: (*int*) Streamline density. Default is 4. :param proj: (*ProjectionInfo*) Map projection of the data. Default is None. :param zorder: (*int*) Z-order of created layer for display. :param select: (*boolean*) Set the return layer as selected layer or not. :returns: (*VectoryLayer*) Created streamline VectoryLayer. """ cmap = plotutil.getcolormap(**kwargs) fill_value = kwargs.pop('fill_value', -9999.0) proj = kwargs.pop('proj', None) cobj = kwargs.pop('color', 'b') color = plotutil.getcolor(cobj) isuv = kwargs.pop('isuv', True) density = kwargs.pop('density', 4) n = len(args) if n < 4: u = args[0] v = args[1] y = u.dimvalue(0) x = u.dimvalue(1) args = args[2:] else: x = args[0] y = args[1] u = args[2] v = args[3] args = args[4:] ls = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Polyline, color, 1) plotutil.setlegendscheme(ls, **kwargs) #layer = __plot_uvgriddata_m(plot, udata, vdata, None, ls, 'streamplot', isuv, proj=proj, density=density) layer = DrawMeteoData.createStreamlineLayer(u.array, v.array, x.array, y.array, density, ls, 'layer', isuv) if not proj is None: layer.setProjInfo(proj) # Add layer isadd = kwargs.pop('isadd', True) if isadd: zorder = kwargs.pop('zorder', None) select = kwargs.pop('select', True) self.add_layer(layer, zorder, select) self.axes.setDrawExtent(layer.getExtent().clone()) self.axes.setExtent(layer.getExtent().clone()) return MILayer(layer)
def getlegendscheme(args, min, max, **kwargs): ls = kwargs.pop('symbolspec', None) if ls is None: cmap = getcolormap(**kwargs) if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createLegendScheme(min, max, cn, cmap) else: if isinstance(level_arg, MIArray): level_arg = level_arg.aslist() ls = LegendManage.createLegendScheme(min, max, level_arg, cmap) else: ls = LegendManage.createLegendScheme(min, max, cmap) ecobj = kwargs.pop('edgecolor', None) if not ecobj is None: edgecolor = getcolor(ecobj) ls = ls.convertTo(ShapeTypes.Polygon) for lb in ls.getLegendBreaks(): lb.setDrawOutline(True) lb.setOutlineColor(edgecolor) return ls
def makelegend(source, **kwargs): ''' Make a legend. :param souce: Legend file name or list of the legen breaks. :returns: Created legend. ''' if isinstance(source, basestring): if os.path.exists(source): ls = LegendScheme() ls.importFromXMLFile(source, False) return ls else: source = getcolormap(source) else: if isinstance(source, list): if isinstance(source[0], ColorBreak): ls = LegendScheme(source) else: colors = getcolors(source) values = kwargs.pop('values', None) if values is None: cbs = [] for c in colors: cb = ColorBreak() cb.setColor(c) cbs.append(cb) ls = LegendScheme(cbs) else: ls = LegendManage.createLegendScheme(values, colors) else: values = kwargs.pop('values', None) if values is None: ls = None else: if isinstance(values, NDArray): values = values.aslist() cbs = source.findBreaks(values) ls = LegendScheme(cbs) return ls
def plot_slice(self, *args, **kwargs): ''' Volume slice planes :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) Optional. Z coordinate array. :param data: (*array_like*) 3D data array. :param xslice: (*list*) X slice locations. :param yslice: (*list*) Y slice locations. :param zslice: (*list*) Z slice locations. :param cmap: (*string*) Color map string. :return: ''' if len(args) <= 3: x = args[0].dimvalue(2) y = args[0].dimvalue(1) z = args[0].dimvalue(0) data = args[0] args = args[1:] else: x = args[0] y = args[1] z = args[2] data = args[3] args = args[4:] if x.ndim == 3: x = x[0, 0] if y.ndim == 3: y = y[0, :, 0] if z.ndim == 3: z = z[:, 0, 0] cmap = plotutil.getcolormap(**kwargs) if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createLegendScheme(data.min(), data.max(), cn, cmap) else: if isinstance(level_arg, NDArray): level_arg = level_arg.aslist() ls = LegendManage.createLegendScheme(data.min(), data.max(), level_arg, cmap) else: ls = LegendManage.createLegendScheme(data.min(), data.max(), cmap) ls = ls.convertTo(ShapeTypes.Polygon) edge = kwargs.pop('edge', True) kwargs['edge'] = edge plotutil.setlegendscheme(ls, **kwargs) 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 = JOGLUtil.slice(data.asarray(), x.asarray(), y.asarray(), z.asarray(), xslice, \ yslice, zslice, ls) 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 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 makesymbolspec(geometry, *args, **kwargs): ''' Make a legend. :param geometry: (*string*) Geometry type. [point | line | polygon]. :param levels: (*array_like*) Value levels. Default is ``None``, not used. :param colors: (*list*) Colors. Defaul is ``None``, not used. :param legend break parameter maps: (*map*) Legend breaks. :param field: (*string*) The field to be used in the legend. :returns: Created legend. ''' shapetype = ShapeTypes.Image if geometry == 'point': shapetype = ShapeTypes.Point elif geometry == 'line': shapetype = ShapeTypes.Polyline elif geometry == 'polygon': shapetype = ShapeTypes.Polygon else: shapetype = ShapeTypes.Image levels = kwargs.pop('levels', None) cols = kwargs.pop('colors', None) field = kwargs.pop('field', '') if not levels is None and not cols is None: if isinstance(levels, MIArray): levels = levels.aslist() colors = [] for cobj in cols: colors.append(getcolor(cobj)) ls = LegendManage.createLegendScheme(shapetype, levels, colors) setlegendscheme(ls, **kwargs) ls.setFieldName(field) values = kwargs.pop('values', None) if values is None: return ls else: nls = LegendScheme(ls.getShapeType()) for v in values: nls.addLegendBreak(ls.findLegendBreak(v)) return nls n = len(args) isunique = True if n == 0: ls = LegendManage.createSingleSymbolLegendScheme(shapetype) setlegendscheme(ls, **kwargs) elif n == 1 and isinstance(args[0], int): ls = LegendManage.createUniqValueLegendScheme(args[0], shapetype) setlegendscheme(ls, **kwargs) else: ls = LegendScheme(shapetype) for arg in args: if isinstance(arg, (list, tuple)): for argi in arg: lb, isu = getlegendbreak(geometry, **argi) if isunique and not isu: isunique = False ls.addLegendBreak(lb) else: lb, isu = getlegendbreak(geometry, **arg) if isunique and not isu: isunique = False ls.addLegendBreak(lb) ls.setFieldName(field) if ls.getBreakNum() > 1: if isunique: ls.setLegendType(LegendType.UniqueValue) else: ls.setLegendType(LegendType.GraduatedColor) return ls
def slice(self, *args, **kwargs): ''' Volume slice planes :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) Optional. Z coordinate array. :param data: (*array_like*) 3D data array. :param xslice: (*list*) X slice locations. :param yslice: (*list*) Y slice locations. :param zslice: (*list*) Z slice locations. :param cmap: (*string*) Color map string. :return: ''' if len(args) <= 3: x = args[0].dimvalue(2) y = args[0].dimvalue(1) z = args[0].dimvalue(0) data = args[0] args = args[1:] else: x = args[0] y = args[1] z = args[2] data = args[3] args = args[4:] if x.ndim == 3: x = x[0, 0] if y.ndim == 3: y = y[0, :, 0] if z.ndim == 3: z = z[:, 0, 0] cmap = plotutil.getcolormap(**kwargs) if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createLegendScheme(data.min(), data.max(), cn, cmap) else: if isinstance(level_arg, NDArray): level_arg = level_arg.aslist() ls = LegendManage.createLegendScheme(data.min(), data.max(), level_arg, cmap) else: ls = LegendManage.createLegendScheme(data.min(), data.max(), cmap) ls = ls.convertTo(ShapeTypes.Polygon) facecolor = kwargs.pop('facecolor', None) face_interp = None if not facecolor is None: face_interp = (facecolor == 'interp') if not face_interp: if not facecolor in ['flat', 'texturemap', 'none']: facecolor = plotutil.getcolor(facecolor) ls = LegendManage.createSingleSymbolLegendScheme( ShapeTypes.Polygon, facecolor, 1) plotutil.setlegendscheme(ls, **kwargs) 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 = JOGLUtil.slice(data.asarray(), x.asarray(), y.asarray(), z.asarray(), xslice, \ yslice, zslice, ls) if face_interp: for gg in graphics: gg.setFaceInterp(face_interp) 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 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. :returns: Legend ''' warnings.warn("plot_surface is deprecated", DeprecationWarning) if len(args) <= 2: 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:] if kwargs.has_key('colors'): cn = len(kwargs['colors']) else: cn = None 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: if cn is None: ls = LegendManage.createLegendScheme(z.min(), z.max(), cmap) else: ls = LegendManage.createLegendScheme(z.min(), z.max(), cn, cmap) ls = ls.convertTo(ShapeTypes.Polygon) facecolor = kwargs.pop('facecolor', None) face_interp = None if not facecolor is None: face_interp = (facecolor == 'interp') if not face_interp: if not facecolor in ['flat', 'texturemap', 'none']: kwargs['facecolor'] = facecolor plotutil.setlegendscheme(ls, **kwargs) graphics = JOGLUtil.surface(x.asarray(), y.asarray(), z.asarray(), ls) if face_interp: graphics.setFaceInterp(face_interp) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
mapFrame.addLayer(countryLayer) #---- Open GrADS data print 'Open GrADS data...' mdi = MeteoDataInfo() mdi.openGrADSData(os.path.join(dataDir, 'model.ctl')) #---- Set time index mdi.setTimeIndex(2) #---- Get pressure grid data gdata = mdi.getGridData('PS') gdata.extendToGlobal() #---- Create legend scheme ls = LegendManage.createLegendSchemeFromGridData(gdata, LegendType.GraduatedColor, ShapeTypes.Polygon) #---- Create pressure shaded layer print 'Create pressure shaded layer...' pressLayer = DrawMeteoData.createShadedLayer(gdata, ls, 'Pressure', 'PS', True) #---- Add layer mapFrame.addLayer(pressLayer) #--- Move pressure layer to bottom mapFrame.moveLayer(pressLayer, 0) #---- Add title title = mapLayout.addText('MeteoInfo script demo - Lambert projection', 350, 30, 'Arial', 16) #---- Project mapview
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 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 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, 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 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 scatter(self, *args, **kwargs): """ Make a scatter plot on a map. :param x: (*array_like*) Input x data. :param y: (*array_like*) Input y data. :param z: (*array_like*) Input z data. :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, different levels will be plotted in different colors in the order specified. :param size: (*int of list*) Marker size. :param marker: (*string*) Marker of the points. :param fill: (*boolean*) Fill markers or not. Default is True. :param edge: (*boolean*) Draw edge of markers or not. Default is True. :param facecolor: (*Color*) Fill color of markers. Default is black. :param edgecolor: (*Color*) Edge color of markers. Default is black. :param proj: (*ProjectionInfo*) Map projection of the data. Default is None. :param zorder: (*int*) Z-order of created layer for display. :returns: (*VectoryLayer*) Point VectoryLayer. """ n = len(args) if n == 1: a = args[0] y = a.dimvalue(0) x = a.dimvalue(1) args = args[1:] else: x = args[0] y = args[1] if not isinstance(x, MIArray): x = minum.array(x) if not isinstance(y, MIArray): y = minum.array(y) if n == 2: a = x args = args[2:] else: a = args[2] if not isinstance(a, MIArray): a = minum.array(a) args = args[3:] ls = kwargs.pop('symbolspec', None) if ls is None: isunique = False colors = kwargs.get('colors', None) if not colors is None: if isinstance(colors, (list, tuple)) and len(colors) == len(x): isunique = True size = kwargs.get('size', None) if not size is None: if isinstance(size, (list, tuple, MIArray)) and len(size) == len(x): isunique = True if isunique: ls = LegendManage.createUniqValueLegendScheme(len(x), ShapeTypes.Point) else: ls = plotutil.getlegendscheme(args, a.min(), a.max(), **kwargs) ls = plotutil.setlegendscheme_point(ls, **kwargs) if a.size == ls.getBreakNum() and ls.getLegendType() == LegendType.UniqueValue: layer = DrawMeteoData.createSTPointLayer_Unique(a.array, x.array, y.array, ls, 'layer', 'data') else: layer = DrawMeteoData.createSTPointLayer(a.array, x.array, y.array, ls, 'layer', 'data') proj = kwargs.pop('proj', None) if not proj is None: layer.setProjInfo(proj) avoidcoll = kwargs.pop('avoidcoll', None) if not avoidcoll is None: layer.setAvoidCollision(avoidcoll) # Add layer isadd = kwargs.pop('isadd', True) if isadd: zorder = kwargs.pop('zorder', None) select = kwargs.pop('select', True) self.add_layer(layer, zorder, select) self.axes.setDrawExtent(layer.getExtent().clone()) self.axes.setExtent(layer.getExtent().clone()) return MILayer(layer)
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)
ynum = 400 xdelt = 0.25 ydelt = 0.25 xlist = [] ylist = [] for i in range(0, xnum): xlist.append(xmin + xdelt * i) for i in range(0, ynum): ylist.append(ymin + ydelt * i) X = jarray.array(xlist, 'd') Y = jarray.array(ylist, 'd') xDim = Dimension(DimensionType.X) xDim.setValues(X) dataInfo.setXDimension(xDim) yDim = Dimension(DimensionType.Y) yDim.setValues(Y) dataInfo.setYDimension(yDim) var = dataInfo.getVariable('precipitation') print var.getName() dimList = [xDim, yDim] var.setDimensions(dimList) gData = mdi.getGridData(var.getName()) aLS = LegendManage.createLegendSchemeFromGridData( gData, LegendType.GraduatedColor, ShapeTypes.Polygon) aLayer = DrawMeteoData.createRasterLayer(gData, "Test_HDF", aLS) mf = miapp.getMapDocument().getActiveMapFrame() mf.addLayer(aLayer) mf.moveLayer(aLayer, 0) print 'Finished!'
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 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 plot_particles(self, *args, **kwargs): ''' creates a three-dimensional particles plot :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param z: (*array_like*) Optional. Z coordinate array. :param data: (*array_like*) 3D data array. :param s: (*float*) Point size. :param cmap: (*string*) Color map string. :param vmin: (*float*) Minimum value for particle plotting. :param vmax: (*float*) Maximum value for particle plotting. :param alpha_min: (*float*) Minimum alpha value. :param alpha_max: (*float*) Maximum alpha value. :param density: (*int*) Particle density value. :returns: Legend ''' if len(args) <= 3: x = args[0].dimvalue(2) y = args[0].dimvalue(1) z = args[0].dimvalue(0) data = args[0] args = args[1:] else: x = args[0] y = args[1] z = args[2] data = args[3] args = args[4:] cmap = plotutil.getcolormap(**kwargs) vmin = kwargs.pop('vmin', data.min()) vmax = kwargs.pop('vmax', data.max()) if vmin >= vmax: raise ValueError("Minimum value larger than maximum value") if len(args) > 0: level_arg = args[0] if isinstance(level_arg, int): cn = level_arg ls = LegendManage.createLegendScheme(vmin, vmax, cn, cmap) else: if isinstance(level_arg, NDArray): level_arg = level_arg.aslist() ls = LegendManage.createLegendScheme(vmin, vmax, level_arg, cmap) else: ls = LegendManage.createLegendScheme(vmin, vmax, cmap) plotutil.setlegendscheme(ls, **kwargs) alpha_min = kwargs.pop('alpha_min', 0.1) alpha_max = kwargs.pop('alpha_max', 0.6) density = kwargs.pop('density', 2) graphics = JOGLUtil.particles(data.asarray(), x.asarray(), y.asarray(), z.asarray(), ls, \ alpha_min, alpha_max, density) s = kwargs.pop('s', None) if s is None: s = kwargs.pop('size', None) if not s is None: graphics.setPointSize(s) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def barbs(self, *args, **kwargs): """ Plot a 2-D field of barbs in a map. :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param u: (*array_like*) U component of the arrow vectors (wind field) or wind direction. :param v: (*array_like*) V component of the arrow vectors (wind field) or wind speed. :param z: (*array_like*) Optional, 2-D z value array. :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level barbs to draw, in increasing order. :param cmap: (*string*) Color map string. :param fill_value: (*float*) Fill_value. Default is ``-9999.0``. :param isuv: (*boolean*) Is U/V or direction/speed data array pairs. Default is True. :param size: (*float*) Base size of the arrows. :param proj: (*ProjectionInfo*) Map projection of the data. Default is None. :param zorder: (*int*) Z-order of created layer for display. :param select: (*boolean*) Set the return layer as selected layer or not. :returns: (*VectoryLayer*) Created barbs VectoryLayer. """ cmap = plotutil.getcolormap(**kwargs) fill_value = kwargs.pop('fill_value', -9999.0) proj = kwargs.pop('proj', None) order = kwargs.pop('order', None) isuv = kwargs.pop('isuv', True) n = len(args) iscolor = False cdata = None onlyuv = True if n >= 4 and isinstance(args[3], (DimArray, MIArray)): onlyuv = False if onlyuv: u = minum.asarray(args[0]) v = minum.asarray(args[1]) xx = args[0].dimvalue(1) yy = args[0].dimvalue(0) x, y = minum.meshgrid(xx, yy) args = args[2:] if len(args) > 0: cdata = minum.asarray(args[0]) iscolor = True args = args[1:] else: x = minum.asarray(args[0]) y = minum.asarray(args[1]) u = minum.asarray(args[2]) v = minum.asarray(args[3]) args = args[4:] if len(args) > 0: cdata = minum.asarray(args[0]) iscolor = True args = args[1:] 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 = cdata.array layer = DrawMeteoData.createBarbLayer(x.array, y.array, u.array, v.array, cdata, ls, 'layer', isuv) if not proj is None: layer.setProjInfo(proj) # Add layer isadd = kwargs.pop('isadd', True) if isadd: zorder = kwargs.pop('zorder', None) select = kwargs.pop('select', True) self.add_layer(layer, zorder, select) self.axes.setDrawExtent(layer.getExtent().clone()) self.axes.setExtent(layer.getExtent().clone()) return MILayer(layer)