def set_title(self, label, fontname=None, fontsize=14, bold=True, color='black'): """ Add a centered title to the figure. :param label: (*string*) Title label string. :param fontname: (*string*) Font name. Default is ``Arial`` . :param fontsize: (*int*) Font size. Default is ``14`` . :param bold: (*boolean*) Is bold font or not. Default is ``True`` . :param color: (*color*) Title string color. Default is ``black`` . """ exfont = False if fontname is None: fontname = 'Arial' else: exfont = True if bold: font = Font(fontname, Font.BOLD, fontsize) else: font = Font(fontname, Font.PLAIN, fontsize) c = plotutil.getcolor(color) ctitle = ChartText(label, font) ctitle.setUseExternalFont(exfont) ctitle.setColor(c) self.getChart().setTitle(ctitle) return ctitle
def set_zticklabels(self, labels, **kwargs): ''' Set z axis tick labels. ''' axis = self.axes.getZAxis() if not labels is None: if isinstance(labels, (MIArray, DimArray)): labels = labels.aslist() if isinstance(labels[0], (int, long, float)): axis.setTickLabels_Number(labels) else: axis.setTickLabelText(labels) fontname = kwargs.pop('fontname', axis.getTickLabelFont().getName()) fontsize = kwargs.pop('fontsize', axis.getTickLabelFont().getSize()) bold =kwargs.pop('bold', axis.getTickLabelFont().isBold()) if bold: font = Font(fontname, Font.BOLD, fontsize) else: font = Font(fontname, Font.PLAIN, fontsize) color = kwargs.pop('color', axis.getTickLabelColor()) c = plotutil.getcolor(color) angle = kwargs.pop('rotation', 0) if angle == 'vertical': angle = 90 axis.setTickLabelFont(font) axis.setTickLabelColor(c) axis.setTickLabelAngle(angle)
def set_zticklabels(self, labels, **kwargs): ''' Set z axis tick labels. ''' axis = self.axes.getZAxis() if not labels is None: if isinstance(labels, (NDArray, DimArray)): labels = labels.aslist() if isinstance(labels[0], (int, long, float)): axis.setTickLabels_Number(labels) else: axis.setTickLabelText(labels) fontname = kwargs.pop('fontname', axis.getTickLabelFont().getName()) fontsize = kwargs.pop('fontsize', axis.getTickLabelFont().getSize()) bold = kwargs.pop('bold', axis.getTickLabelFont().isBold()) if bold: font = Font(fontname, Font.BOLD, fontsize) else: font = Font(fontname, Font.PLAIN, fontsize) color = kwargs.pop('color', axis.getTickLabelColor()) c = plotutil.getcolor(color) angle = kwargs.pop('rotation', 0) if angle == 'vertical': angle = 90 axis.setTickLabelFont(font) axis.setTickLabelColor(c) axis.setTickLabelAngle(angle)
def set_background(self, color): ''' Set background color. :param color: (*color*) Background color. ''' color = plotutil.getcolor(color) self.axes.setBackground(color)
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 zaxis(self, **kwargs): """ Set z axis of the axes. :param color: (*Color*) Color of the z axis. Default is 'black'. :param shift: (*int) z axis shif along horizontal direction. Units is pixel. Default is 0. """ visible = kwargs.pop('visible', None) shift = kwargs.pop('shift', None) color = kwargs.pop('color', None) if not color is None: color = plotutil.getcolor(color) linewidth = kwargs.pop('linewidth', None) linestyle = kwargs.pop('linestyle', None) tickline = kwargs.pop('tickline', None) tickline = kwargs.pop('tickvisible', tickline) tickwidth = kwargs.pop('tickwidth', None) ticklabel = kwargs.pop('ticklabel', None) minortick = kwargs.pop('minortick', False) minorticknum = kwargs.pop('minorticknum', 5) tickin = kwargs.pop('tickin', True) axistype = kwargs.pop('axistype', None) tickfontname = kwargs.pop('tickfontname', 'Arial') tickfontsize = kwargs.pop('tickfontsize', 14) tickbold = kwargs.pop('tickbold', False) if tickbold: font = Font(tickfontname, Font.BOLD, tickfontsize) else: font = Font(tickfontname, Font.PLAIN, tickfontsize) axislist = [] axislist.append(self.axes.getZAxis()) for axis in axislist: if not visible is None: axis.setVisible(visible) if not shift is None: axis.setShift(shift) if not color is None: axis.setColor_All(color) if not linewidth is None: axis.setLineWidth(linewidth) if not linestyle is None: axis.setLineStyle(linestyle) if not tickline is None: axis.setDrawTickLine(tickline) if not tickwidth is None: stroke = BasicStroke(tickwidth) axis.setTickStroke(stroke) if not ticklabel is None: axis.setDrawTickLabel(ticklabel) axis.setMinorTickVisible(minortick) axis.setMinorTickNum(minorticknum) axis.setInsideTick(tickin) axis.setTickLabelFont(font)
def __init__(self, *args, **kwargs): """ Axes 3d with openGL support. :param position: (*list of float*) Axes position specified by *position=* [left, bottom, width height] in normalized (0, 1) units. Default is [0.13, 0.11, 0.775, 0.815]. :param rotation: (*float*) Axes rotation angle around Z axis. :param elevation: (*float*) Axes elevation angle with Z axis. :param antialias: (*bool*) Antialias or not. Default is `None`. """ axes = kwargs.pop('axes', None) self._set_plot(axes) figure = kwargs.pop('figure', None) self.figure = figure if len(args) > 0: position = args[0] else: position = kwargs.pop('position', None) outerposition = kwargs.pop('outerposition', None) if position is None: position = [0.13, 0.11, 0.71, 0.815] self.active_outerposition(True) else: self.active_outerposition(False) self.set_position(position) if not outerposition is None: self.set_outerposition(outerposition) self.active_outerposition(True) bgcolor = kwargs.pop('bgcolor', None) if not bgcolor is None: bgcolor = plotutil.getcolor(bgcolor) self.axes.setBackground(bgcolor) units = kwargs.pop('units', None) if not units is None: self.axes.setUnits(units) tickfontname = kwargs.pop('tickfontname', 'Arial') tickfontsize = kwargs.pop('tickfontsize', 14) tickbold = kwargs.pop('tickbold', False) if tickbold: font = Font(tickfontname, Font.BOLD, tickfontsize) else: font = Font(tickfontname, Font.PLAIN, tickfontsize) self.axes.setAxisTickFont(font) rotation = kwargs.pop('rotation', None) if not rotation is None: self.axes.setAngleY(rotation) elevation = kwargs.pop('elevation', None) if not elevation is None: self.axes.setAngleX(elevation) antialias = kwargs.pop('antialias', None) if not antialias is None: self.axes.setAntialias(antialias)
def zaxis(self, **kwargs): """ Set z axis of the axes. :param color: (*Color*) Color of the z axis. Default is 'black'. :param shift: (*int) z axis shif along horizontal direction. Units is pixel. Default is 0. """ visible = kwargs.pop('visible', None) shift = kwargs.pop('shift', None) color = kwargs.pop('color', None) if not color is None: color = plotutil.getcolor(color) linewidth = kwargs.pop('linewidth', None) linestyle = kwargs.pop('linestyle', None) tickline = kwargs.pop('tickline', None) tickline = kwargs.pop('tickvisible', tickline) ticklabel = kwargs.pop('ticklabel', None) minortick = kwargs.pop('minortick', False) minorticknum = kwargs.pop('minorticknum', 5) tickin = kwargs.pop('tickin', True) axistype = kwargs.pop('axistype', None) tickfontname = kwargs.pop('tickfontname', 'Arial') tickfontsize = kwargs.pop('tickfontsize', 14) tickbold = kwargs.pop('tickbold', False) if tickbold: font = Font(tickfontname, Font.BOLD, tickfontsize) else: font = Font(tickfontname, Font.PLAIN, tickfontsize) axislist = [] axislist.append(self.axes.getZAxis()) for axis in axislist: if not visible is None: axis.setVisible(visible) if not shift is None: axis.setShift(shift) if not color is None: axis.setColor_All(color) if not linewidth is None: axis.setLineWidth(linewidth) if not linestyle is None: axis.setLineStyle(linestyle) if not tickline is None: axis.setDrawTickLine(tickline) if not ticklabel is None: axis.setDrawTickLabel(ticklabel) axis.setMinorTickVisible(minortick) axis.setMinorTickNum(minorticknum) axis.setInsideTick(tickin) axis.setTickLabelFont(font)
def __init__(self, figsize=None, dpi=None, bgcolor='w'): ''' Constructor :param figsize: (*list*) Optional, width and height of the figure such as ``[600, 400]``. :param bgcolor: (*Color*) Optional, background color of the figure. Default is ``w`` (white). :param dpi: (*int*) Dots per inch. ''' chart = Chart() chart.setBackground(plotutil.getcolor(bgcolor)) if figsize is None: super(Figure, self).__init__(chart) else: super(Figure, self).__init__(chart, figsize[0], figsize[1]) self.axes = [] self.current_axes = -1
def grid(self, b=None, which='major', axis='both', **kwargs): """ Turn the aexs grids on or off. :param b: If b is *None* and *len(kwargs)==0* , toggle the grid state. If *kwargs* are supplied, it is assumed that you want a grid and *b* is thus set to *True* . :param which: *which* can be 'major' (default), 'minor', or 'both' to control whether major tick grids, minor tick grids, or both are affected. :param axis: *axis* can be 'both' (default), 'x', or 'y' to control which set of gridlines are drawn. :param kwargs: *kwargs* are used to set the grid line properties. """ if self.islonlat(): super(MapAxes, self).grid(b, which, axis, **kwargs) else: mapframe = self.axes.getMapFrame() gridline = mapframe.isDrawGridLine() if b is None: gridline = not gridline else: gridline = b griddx = kwargs.pop('griddx', None) griddy = kwargs.pop('griddy', None) if not gridline is None: mapframe.setDrawGridLine(gridline) if not griddx is None: mapframe.setGridXDelt(griddx) if not griddy is None: mapframe.setGridYDelt(griddy) color = kwargs.pop('color', None) if not color is None: c = plotutil.getcolor(color) mapframe.setGridLineColor(c) linewidth = kwargs.pop('linewidth', None) if not linewidth is None: mapframe.setGridLineSize(linewidth) linestyle = kwargs.pop('linestyle', None) if not linestyle is None: linestyle = plotutil.getlinestyle(linestyle) mapframe.setGridLineStyle(linestyle)
def __set_axes(self, ax, **kwargs): """ Set an axes. :param aspect: (*string*) ['equal' | 'auto'] or a number. If a number the ratio of x-unit/y-unit in screen-space. Default is 'auto'. :param bgcolor: (*Color*) Optional, axes background color. :param axis: (*boolean*) Optional, set all axis visible or not. Default is ``True`` . :param bottomaxis: (*boolean*) Optional, set bottom axis visible or not. Default is ``True`` . :param leftaxis: (*boolean*) Optional, set left axis visible or not. Default is ``True`` . :param topaxis: (*boolean*) Optional, set top axis visible or not. Default is ``True`` . :param rightaxis: (*boolean*) Optional, set right axis visible or not. Default is ``True`` . :param xaxistype: (*string*) Optional, set x axis type as 'normal', 'lon', 'lat' or 'time'. :param xreverse: (*boolean*) Optional, set x axis reverse or not. Default is ``False`` . :param yreverse: (*boolean*) Optional, set yaxis reverse or not. Default is ``False`` . :returns: The axes. """ aspect = kwargs.pop('aspect', 'auto') axis = kwargs.pop('axis', True) b_axis = ax.get_axis(Location.BOTTOM) l_axis = ax.get_axis(Location.LEFT) t_axis = ax.get_axis(Location.TOP) r_axis = ax.get_axis(Location.RIGHT) if axis: bottomaxis = kwargs.pop('bottomaxis', True) leftaxis = kwargs.pop('leftaxis', True) topaxis = kwargs.pop('topaxis', True) rightaxis = kwargs.pop('rightaxis', True) else: bottomaxis = False leftaxis = False topaxis = False rightaxis = False xreverse = kwargs.pop('xreverse', False) yreverse = kwargs.pop('yreverse', False) xaxistype = kwargs.pop('xaxistype', None) bgcobj = kwargs.pop('bgcolor', None) if aspect == 'equal': ax.axes.setAutoAspect(False) else: if isinstance(aspect, (int, float)): ax.axes.setAspect(aspect) ax.axes.setAutoAspect(False) if bottomaxis == False: b_axis.setVisible(False) if leftaxis == False: l_axis.setVisible(False) if topaxis == False: t_axis.setVisible(False) if rightaxis == False: r_axis.setVisible(False) if xreverse: b_axis.setInverse(True) t_axis.setInverse(True) if yreverse: l_axis.setInverse(True) r_axis.setInverse(True) if not xaxistype is None: ax.set_xaxis_type(xaxistype) bgcolor = plotutil.getcolor(bgcobj) ax.axes.setBackground(bgcolor) tickline = kwargs.pop('tickline', True) b_axis.setDrawTickLine(tickline) t_axis.setDrawTickLine(tickline) l_axis.setDrawTickLine(tickline) r_axis.setDrawTickLine(tickline) tickfontname = kwargs.pop('tickfontname', 'Arial') tickfontsize = kwargs.pop('tickfontsize', 14) tickbold = kwargs.pop('tickbold', False) if tickbold: font = Font(tickfontname, Font.BOLD, tickfontsize) else: font = Font(tickfontname, Font.PLAIN, tickfontsize) ax.axes.setAxisLabelFont(font)
def text(self, x, y, z, s, zdir=None, **kwargs): ''' Add text to the plot. kwargs will be passed on to text, except for the zdir keyword, which sets the direction to be used as the z direction. :param x: (*float*) X coordinate. :param y: (*float*) Y coordinate. :param z: (*float*) Z coordinate. :param s: (*string*) Text string. :param zdir: Z direction. ''' fontname = kwargs.pop('fontname', 'Arial') fontsize = kwargs.pop('fontsize', 14) bold = kwargs.pop('bold', False) color = kwargs.pop('color', 'black') if bold: font = Font(fontname, Font.BOLD, fontsize) else: font = Font(fontname, Font.PLAIN, fontsize) c = plotutil.getcolor(color) text = ChartText3D() text.setText(s) text.setFont(font) text.setColor(c) text.setPoint(x, y, z) ha = kwargs.pop('horizontalalignment', None) if ha is None: ha = kwargs.pop('ha', None) if not ha is None: text.setXAlign(ha) va = kwargs.pop('verticalalignment', None) if va is None: va = kwargs.pop('va', None) if not va is None: text.setYAlign(va) bbox = kwargs.pop('bbox', None) if not bbox is None: fill = bbox.pop('fill', None) if not fill is None: text.setFill(fill) facecolor = bbox.pop('facecolor', None) if not facecolor is None: facecolor = plotutil.getcolor(facecolor) text.setFill(True) text.setBackground(facecolor) edge = bbox.pop('edge', None) if not edge is None: text.setDrawNeatline(edge) edgecolor = bbox.pop('edgecolor', None) if not edgecolor is None: edgecolor = plotutil.getcolor(edgecolor) text.setNeatlineColor(edgecolor) text.setDrawNeatline(True) linewidth = bbox.pop('linewidth', None) if not linewidth is None: text.setNeatlineSize(linewidth) text.setDrawNeatline(True) gap = bbox.pop('gap', None) if not gap is None: text.setGap(gap) if not zdir is None: if isinstance(zdir, (list, tuple)): text.setZDir(zdir[0], zdir[1], zdir[2]) else: text.setZDir(zdir) graphic = Graphic(text, None) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphic) return graphic
def surf(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 lighting: (*bool*) Using light or not. :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) 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) graphics = JOGLUtil.surface(x.asarray(), y.asarray(), z.asarray(), ls) if face_interp: graphics.setFaceInterp(face_interp) lighting = kwargs.pop('lighting', None) if not lighting is None: graphics.setUsingLight(lighting) visible = kwargs.pop('visible', True) if visible: self.add_graphic(graphics) return graphics
def __set_axesm(self, ax, **kwargs): """ Create an map axes. :param bgcolor: (*Color*) Optional, axes background color. :param axis: (*boolean*) Optional, set all axis visible or not. Default is ``True`` . :param bottomaxis: (*boolean*) Optional, set bottom axis visible or not. Default is ``True`` . :param leftaxis: (*boolean*) Optional, set left axis visible or not. Default is ``True`` . :param topaxis: (*boolean*) Optional, set top axis visible or not. Default is ``True`` . :param rightaxis: (*boolean*) Optional, set right axis visible or not. Default is ``True`` . :param xyscale: (*int*) Optional, set scale of x and y axis, default is 1. It is only valid in longlat projection. :param gridlabel: (*boolean*) Optional, set axis tick labels visible or not. Default is ``True`` . :param gridlabelloc: (*string*) Optional, Set grid label locations [left_bottom | left_up | right_bottom | right_up | all]. Default is ``left_bottom'. :param gridline: (*boolean*) Optional, set grid line visible or not. Default is ``False`` . :param griddx: (*float*) Optional, set x grid line interval. Default is 10 degree. :param griddy: (*float*) Optional, set y grid line interval. Default is 10 degree. :param frameon: (*boolean*) Optional, set frame visible or not. Default is ``False`` for lon/lat projection, ortherwise is ``True``. :param tickfontname: (*string*) Optional, set axis tick labels font name. Default is ``Arial`` . :param tickfontsize: (*int*) Optional, set axis tick labels font size. Default is 14. :param tickbold: (*boolean*) Optional, set axis tick labels font bold or not. Default is ``False`` . :param boundaryprop: (*dict*) boundary property. :returns: The map axes. """ aspect = kwargs.pop('aspect', 'equal') if aspect == 'equal': ax.axes.setAutoAspect(False) elif aspect == 'auto': ax.axes.setAutoAspect(True) else: if isinstance(aspect, (int, float)): ax.axes.setAspect(aspect) ax.axes.setAutoAspect(False) axis = kwargs.pop('axis', True) if axis: bottomaxis = kwargs.pop('bottomaxis', True) leftaxis = kwargs.pop('leftaxis', True) topaxis = kwargs.pop('topaxis', True) rightaxis = kwargs.pop('rightaxis', True) else: bottomaxis = False leftaxis = False topaxis = False rightaxis = False gridlabel = kwargs.pop('gridlabel', True) gridlabelloc = kwargs.pop('gridlabelloc', 'left_bottom') gridline = kwargs.pop('gridline', False) griddx = kwargs.pop('griddx', 10) griddy = kwargs.pop('griddy', 10) if ax.axes.getProjInfo().isLonLat(): frameon = kwargs.pop('frameon', False) else: frameon = kwargs.pop('frameon', True) axison = kwargs.pop('axison', None) bgcobj = kwargs.pop('bgcolor', None) xyscale = kwargs.pop('xyscale', 1) tickfontname = kwargs.pop('tickfontname', 'Arial') tickfontsize = kwargs.pop('tickfontsize', 14) tickbold = kwargs.pop('tickbold', False) if tickbold: font = Font(tickfontname, Font.BOLD, tickfontsize) else: font = Font(tickfontname, Font.PLAIN, tickfontsize) mapview = ax.axes.getMapView() mapview.setXYScaleFactor(xyscale) ax.axes.setAspect(xyscale) ax.axes.setAxisLabelFont(font) if not axison is None: ax.axes.setAxisOn(axison) else: if bottomaxis == False: ax.axes.getAxis(Location.BOTTOM).setVisible(False) if leftaxis == False: ax.axes.getAxis(Location.LEFT).setVisible(False) if topaxis == False: ax.axes.getAxis(Location.TOP).setVisible(False) if rightaxis == False: ax.axes.getAxis(Location.RIGHT).setVisible(False) mapframe = ax.axes.getMapFrame() mapframe.setGridFont(font) mapframe.setDrawGridLabel(gridlabel) mapframe.setDrawGridTickLine(gridlabel) mapframe.setGridLabelPosition(gridlabelloc) mapframe.setDrawGridLine(gridline) mapframe.setGridXDelt(griddx) mapframe.setGridYDelt(griddy) ax.axes.setDrawNeatLine(frameon) bgcolor = plotutil.getcolor(bgcobj) ax.axes.setBackground(bgcolor) boundaryprop = kwargs.pop('boundaryprop', None) if not boundaryprop is None: boundaryprop = plotutil.getlegendbreak('polygon', **boundaryprop)[0] ax.axes.setBoundaryProp(boundaryprop) return ax
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 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 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