Exemplo n.º 1
0
    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]
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
 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]