def getlegendbreak(geometry, **kwargs): cobj = kwargs.pop('color', None) if cobj is None: cobj = kwargs.pop('facecolor', None) color = None if not cobj is None: color = getcolor(cobj) if geometry == 'point': lb = PointBreak() marker = kwargs.pop('marker', 'o') if marker == 'image': imagepath = kwargs.pop('imagepath', None) if not imagepath is None: lb.setMarkerType(MarkerType.Image) lb.setImagePath(imagepath) elif marker == 'font': fontname = kwargs.pop('fontname', 'Weather') lb.setMarkerType(MarkerType.Character) lb.setFontName(fontname) charindex = kwargs.pop('charindex', 0) lb.setCharIndex(charindex) else: pstyle = getpointstyle(marker) lb.setStyle(pstyle) size = kwargs.pop('size', 6) lb.setSize(size) ecobj = kwargs.pop('edgecolor', 'k') edgecolor = getcolor(ecobj) lb.setOutlineColor(edgecolor) edgesize = kwargs.pop('edgesize', 1) lb.setOutlineSize(edgesize) fill = kwargs.pop('fill', True) lb.setDrawFill(fill) edge = kwargs.pop('edge', True) lb.setDrawOutline(edge) elif geometry == 'line': lb = PolylineBreak() size = kwargs.pop('size', 1.0) size = kwargs.pop('linewidth', size) lb.setWidth(size) lsobj = kwargs.pop('linestyle', '-') linestyle = getlinestyle(lsobj) lb.setStyle(linestyle) marker = kwargs.pop('marker', None) if not marker is None: pstyle = getpointstyle(marker) lb.setDrawSymbol(True) lb.setSymbolStyle(pstyle) markersize = kwargs.pop('markersize', None) if not markersize is None: lb.setSymbolSize(markersize) markercolor = kwargs.pop('markercolor', None) if not markercolor is None: markercolor = getcolor(markercolor) lb.setSymbolColor(markercolor) fillcolor = kwargs.pop('makerfillcolor', None) if not fillcolor is None: lb.setFillSymbol(True) lb.setSymbolFillColor(getcolor(fillcolor)) else: lb.setSymbolFillColor(markercolor) interval = kwargs.pop('markerinterval', 1) lb.setSymbolInterval(interval) elif geometry == 'polygon': lb = PolygonBreak() ecobj = kwargs.pop('edgecolor', 'k') edgecolor = getcolor(ecobj) lb.setOutlineColor(edgecolor) fill = kwargs.pop('fill', None) if fill is None: if color is None: lb.setDrawFill(False) else: lb.setDrawFill(True) else: lb.setDrawFill(fill) edge = kwargs.pop('edge', True) lb.setDrawOutline(edge) size = kwargs.pop('size', None) size = kwargs.pop('edgesize', size) if not size is None: lb.setOutlineSize(size) hatch = kwargs.pop('hatch', None) hatch = gethatch(hatch) hatchsize = kwargs.pop('hatchsize', None) bgcolor = kwargs.pop('bgcolor', None) bgcolor = getcolor(bgcolor) if not hatch is None: lb.setStyle(hatch) if not bgcolor is None: lb.setBackColor(bgcolor) if not hatchsize is None: lb.setStyleSize(hatchsize) else: lb = ColorBreak() caption = kwargs.pop('caption', None) if not caption is None: lb.setCaption(caption) if not color is None: lb.setColor(color) alpha = kwargs.pop('alpha', None) if not alpha is None: lb.setColor(getcolor(lb.getColor(), alpha)) value = kwargs.pop('value', None) isunique = True if not value is None: if isinstance(value, (tuple, list)): lb.setStartValue(value[0]) lb.setEndValue(value[1]) isunique = False else: lb.setStartValue(value) lb.setEndValue(value) return lb, isunique
def getplotstyle(style, caption, **kwargs): linewidth = kwargs.pop('linewidth', 1.0) if style is None: color = kwargs.pop('color', 'red') c = getcolor(color) else: c, style = getcolor_style(style) lineStyle, style = getlinestyle_1(style) pointStyle = getpointstyle(style) if not pointStyle is None: fill = kwargs.pop('fill', True) if lineStyle is None: pb = PointBreak() pb.setCaption(caption) if '.' in style: pb.setSize(4) pb.setDrawOutline(False) else: pb.setSize(8) pb.setStyle(pointStyle) pb.setDrawFill(fill) if not c is None: pb.setColor(c) edgecolor = kwargs.pop('edgecolor', pb.getColor()) edgecolor = getcolor(edgecolor) pb.setOutlineColor(edgecolor) return pb else: plb = PolylineBreak() plb.setCaption(caption) plb.setWidth(linewidth) plb.setStyle(lineStyle) plb.setDrawSymbol(True) plb.setSymbolStyle(pointStyle) plb.setFillSymbol(fill) interval = kwargs.pop('markerinterval', 1) plb.setSymbolInterval(interval) if not c is None: plb.setColor(c) markersize = kwargs.pop('markersize', None) if not markersize is None: plb.setSymbolSize(markersize) markercolor = kwargs.pop('markercolor', plb.getColor()) markercolor = getcolor(markercolor) plb.setSymbolColor(markercolor) markerfillcolor = kwargs.pop('markerfillcolor', markercolor) markerfillcolor = getcolor(markerfillcolor) plb.setSymbolFillColor(markerfillcolor) return plb else: plb = PolylineBreak() plb.setCaption(caption) plb.setWidth(linewidth) if not c is None: plb.setColor(c) if not lineStyle is None: plb.setStyle(lineStyle) return plb
mdi.setTimeIndex(2) #---- Get pressure grid data gdata = mdi.getGridData('PS') gdata.extendToGlobal() #---- Create layer print 'Create layer...' ls = LegendScheme(ShapeTypes.Polyline) ls.setLegendType(LegendType.UniqueValue) values = [500, 550, 600, 650, 700, 750, 800, 850, 900, 950,1000] colors = [Color(110,0,220),Color(30,60,255),Color(0,160,255),Color(0,200,200),Color(0,220,0), Color(160,230,50),Color(230,220,50),Color(230,175,45),Color(240,130,40),Color(250,60,60),Color(240,0,130)] lbs = ls.getLegendBreaks() for i in range(0, len(colors)): lb = PolylineBreak() lb.setColor(colors[i]) lb.setStartValue(values[i]) lb.setEndValue(values[i]) lb.setCaption(str(values[i])) lbs.add(lb) layer = DrawMeteoData.createContourLayer(gdata, ls, 'Pressure_contour', 'PS', True) #---- Add layer mapFrame.addLayer(layer) mapFrame.moveLayer(layer, 0) #---- Add title title = mapLayout.addText('MeteoInfo script demo', 350, 30, 'Arial', 16)
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 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]