Beispiel #1
0
    def __init__(self,
                 edgecolors=None,
                 facecolors=None,
                 linewidths=None,
                 antialiaseds = None,
                 offsets = None,
                 transOffset = identity_transform(),
                 norm = None,  # optional for ScalarMappable
                 cmap = None,  # ditto
                 ):
        Collection.__init__(self)
        ScalarMappable.__init__(self, norm, cmap)

        if edgecolors is None: edgecolors =\
           self._get_color(rcParams['patch.edgecolor'])
        if facecolors is None: facecolors = \
           self._get_color(rcParams['patch.facecolor'])
        if linewidths is None: linewidths = ( rcParams['patch.linewidth'],)
        if antialiaseds is None: antialiaseds = ( rcParams['patch.antialiased'],)

        self._edgecolors = edgecolors
        self._facecolors  = facecolors
        self._linewidths  = linewidths
        self._antialiaseds = antialiaseds
        self._offsets = offsets
        self._transOffset = transOffset
Beispiel #2
0
    def __init__(self,
                 edgecolors=None,
                 facecolors=None,
                 linewidths=None,
                 antialiaseds = None,
                 offsets = None,
                 transOffset = identity_transform(),
                 norm = None,  # optional for ScalarMappable
                 cmap = None,  # ditto
                 ):
        Collection.__init__(self)
        ScalarMappable.__init__(self, norm, cmap)

        if edgecolors is None: edgecolors =\
           self._get_color(rcParams['patch.edgecolor'])
        if facecolors is None: facecolors = \
           self._get_color(rcParams['patch.facecolor'])
        if linewidths is None: linewidths = ( rcParams['patch.linewidth'],)
        if antialiaseds is None: antialiaseds = ( rcParams['patch.antialiased'],)

        self._edgecolors = edgecolors
        self._facecolors  = facecolors
        self._linewidths  = linewidths
        self._antialiaseds = antialiaseds
        self._offsets = offsets
        self._transOffset = transOffset
Beispiel #3
0
    def __init__(self, levels, collections, norm=None, cmap=None, labeld=None):
        """
        See comment on labeld in the ContourLabeler class

        """
        ScalarMappable.__init__(self, norm, cmap)
        self.levels = levels
        self.collections = collections
        if labeld is None: labeld = {}
        self.labeld = labeld
Beispiel #4
0
    def __init__(self, levels, collections, norm=None, cmap=None, labeld=None):
        """
        See comment on labeld in the ContourLabeler class

        """
        ScalarMappable.__init__(self, norm, cmap)
        self.levels = levels
        self.collections = collections
        if labeld is None: labeld = {}
        self.labeld = labeld
Beispiel #5
0
    def __init__(
            self,
            edgecolors=None,
            facecolors=None,
            linewidths=None,
            antialiaseds=None,
            offsets=None,
            transOffset=identity_transform(),
            norm=None,  # optional for ScalarMappable
            cmap=None,  # ditto
    ):
        Collection.__init__(self)
        ScalarMappable.__init__(self, norm, cmap)

        if facecolors is None: facecolors = rcParams['patch.facecolor']
        if edgecolors is None: edgecolors = rcParams['patch.edgecolor']
        if linewidths is None: linewidths = (rcParams['patch.linewidth'], )
        if antialiaseds is None:
            antialiaseds = (rcParams['patch.antialiased'], )

        self._facecolors = colorConverter.to_rgba_list(facecolors)
        if edgecolors == 'None':
            self._edgecolors = self._facecolors
            linewidths = (0, )
        else:
            self._edgecolors = colorConverter.to_rgba_list(edgecolors)
        self._linewidths = linewidths
        self._antialiaseds = antialiaseds
        #self._offsets = offsets
        self._original_offsets = offsets
        self._cached_offsets = offsets
        self._transOffset = transOffset
        self._xunits = self._yunits = None
        self._update_cache = {
            '_original_offsets': None,
            '_xunits': None,
            '_yunits': None
        }
Beispiel #6
0
    def __init__(self, ax, *args, **kwargs):
        """
        Draw contour lines or filled regions, depending on
        whether keyword arg 'filled' is False (default) or True.

        The first argument of the initializer must be an axes
        object.  The remaining arguments and keyword arguments
        are described in ContourSet.contour_doc.

        """
        self.ax = ax
        self.filled = kwargs.get('filled', False)
        self.linewidths = kwargs.get('linewidths', None)

        self.alpha = kwargs.get('alpha', 1.0)
        self.origin = kwargs.get('origin', None)
        self.extent = kwargs.get('extent', None)
        cmap = kwargs.get('cmap', None)
        self.colors = kwargs.get('colors', None)
        norm = kwargs.get('norm', None)
        self.clip_ends = kwargs.get('clip_ends', True)
        self.antialiased = kwargs.get('antialiased', True)
        self.nchunk = kwargs.get('nchunk', 0)

        if self.origin is not None: assert(self.origin in
                                            ['lower', 'upper', 'image'])
        if self.extent is not None: assert(len(self.extent) == 4)
        if cmap is not None: assert(isinstance(cmap, Colormap))
        if self.colors is not None and cmap is not None:
            raise ValueError('Either colors or cmap must be None')
        if self.origin == 'image': self.origin = rcParams['image.origin']
        x, y, z = self._contour_args(*args)        # also sets self.levels,
                                                   #  self.layers
        if self.colors is not None:
            cmap = ListedColormap(self.colors, N=len(self.layers))
        if self.filled:
            self.collections = silent_list('PolyCollection')
        else:
            self.collections = silent_list('LineCollection')
        # label lists must be initialized here
        self.cl = []
        self.cl_cvalues = []

        kw = {'cmap': cmap}
        if norm is not None:
            kw['norm'] = norm
        ScalarMappable.__init__(self, **kw) # sets self.cmap;
        self._process_colors()

        if self.filled:
            if self.linewidths is None:
                self.linewidths = 0.05 # Good default for Postscript.
            if iterable(self.linewidths):
                self.linewidths = self.linewidths[0]
            #C = _contour.Cntr(x, y, z.filled(), z.mask())
            C = _contour.Cntr(x, y, z.filled(), ma.getmaskorNone(z))
            lowers = self.levels[:-1]
            uppers = self.levels[1:]
            for level, level_upper, color in zip(lowers, uppers, self.tcolors):
                nlist = C.trace(level, level_upper, points = 1,
                        nchunk = self.nchunk)
                col = PolyCollection(nlist,
                                     linewidths = (self.linewidths,),
                                     antialiaseds = (self.antialiased,))
                col.set_color(color) # sets both facecolor and edgecolor
                self.ax.add_collection(col)
                self.collections.append(col)

        else:
            tlinewidths = self._process_linewidths()
            #C = _contour.Cntr(x, y, z.filled(), z.mask())
            C = _contour.Cntr(x, y, z.filled(), ma.getmaskorNone(z))
            for level, color, width in zip(self.levels, self.tcolors, tlinewidths):
                nlist = C.trace(level, points = 1)
                col = LineCollection(nlist)
                col.set_color(color)
                col.set_linewidth(width)

                if level < 0.0 and self.monochrome:
                    col.set_linestyle((0, (6.,6.)),)
                col.set_label(str(level))         # only for self-documentation
                self.ax.add_collection(col)
                self.collections.append(col)

        ## check: seems like set_xlim should also be inside
        if not self.ax.ishold():
            self.ax.cla()
        self.ax.set_xlim((ma.minimum(x), ma.maximum(x)))
        self.ax.set_ylim((ma.minimum(y), ma.maximum(y)))
Beispiel #7
0
    def __init__(
        self,
        segments,  # Can be None.
        linewidths=None,
        colors=None,
        antialiaseds=None,
        linestyle='solid',
        offsets=None,
        transOffset=None,  #identity_transform(),
        norm=None,
        cmap=None,
    ):
        """
        segments is a sequence of ( line0, line1, line2), where
        linen = (x0, y0), (x1, y1), ... (xm, ym), or the
        equivalent numerix array with two columns.
        Each line can be a different length.

        colors must be a tuple of RGBA tuples (eg arbitrary color
        strings, etc, not allowed).

        antialiaseds must be a sequence of ones or zeros

        linestyles is a string or dash tuple. Legal string values are
          solid|dashed|dashdot|dotted.  The dash tuple is (offset, onoffseq)
          where onoffseq is an even length tuple of on and off ink in points.

        If linewidths, colors, or antialiaseds is None, they default to
        their rc params setting, in sequence form.

        If offsets and transOffset are not None, then
        offsets are transformed by transOffset and applied after
        the segments have been transformed to display coordinates.

        If offsets is not None but transOffset is None, then the
        offsets are added to the segments before any transformation.
        In this case, a single offset can be specified as offsets=(xo,yo),
        and this value will be
        added cumulatively to each successive segment, so as
        to produce a set of successively offset curves.

        norm = None,  # optional for ScalarMappable
        cmap = None,  # ditto

        The use of ScalarMappable is optional.  If the ScalarMappable
        matrix _A is not None (ie a call to set_array has been made), at
        draw time a call to scalar mappable will be made to set the colors.
        """

        Collection.__init__(self)
        ScalarMappable.__init__(self, norm, cmap)

        if linewidths is None:
            linewidths = (rcParams['lines.linewidth'], )

        if colors is None:
            colors = (rcParams['lines.color'], )
        if antialiaseds is None:
            antialiaseds = (rcParams['lines.antialiased'], )

        self._colors = colorConverter.to_rgba_list(colors)
        self._aa = antialiaseds
        self._lw = linewidths
        self.set_linestyle(linestyle)
        self._uniform_offsets = None
        if offsets is not None:
            offsets = asarray(offsets)
            if len(offsets.shape) == 1:
                offsets = offsets[newaxis, :]  # Make it Nx2.
        if transOffset is None:
            if offsets is not None:
                self._uniform_offsets = offsets
                offsets = None
            transOffset = identity_transform()
        self._offsets = offsets
        self._transOffset = transOffset
        self.set_segments(segments)
Beispiel #8
0
    def __init__(self, ax, *args, **kwargs):
        """
        Draw contour lines or filled regions, depending on
        whether keyword arg 'filled' is False (default) or True.

        The first argument of the initializer must be an axes
        object.  The remaining arguments and keyword arguments
        are described in ContourSet.contour_doc.

        """
        self.ax = ax
        self.levels = kwargs.get('levels', None)
        self.filled = kwargs.get('filled', False)
        self.linewidths = kwargs.get('linewidths', None)

        self.alpha = kwargs.get('alpha', 1.0)
        self.origin = kwargs.get('origin', None)
        self.extent = kwargs.get('extent', None)
        cmap = kwargs.get('cmap', None)
        self.colors = kwargs.get('colors', None)
        norm = kwargs.get('norm', None)
        self.clip_ends = kwargs.get('clip_ends', None)  ########
        self.extend = kwargs.get('extend', 'neither')
        if self.clip_ends is not None:
            warnings.warn("'clip_ends' has been replaced by 'extend'")
            self.levels = self.levels[1:-1]  # discard specified end levels
            self.extend = 'both'  # regenerate end levels
        self.antialiased = kwargs.get('antialiased', True)
        self.nchunk = kwargs.get('nchunk', 0)
        self.locator = kwargs.get('locator', None)

        if self.origin is not None:
            assert (self.origin in ['lower', 'upper', 'image'])
        if self.extent is not None: assert (len(self.extent) == 4)
        if cmap is not None: assert (isinstance(cmap, Colormap))
        if self.colors is not None and cmap is not None:
            raise ValueError('Either colors or cmap must be None')
        if self.origin == 'image': self.origin = rcParams['image.origin']
        x, y, z = self._contour_args(*args)  # also sets self.levels,
        #  self.layers
        if self.colors is not None:
            cmap = ListedColormap(self.colors, N=len(self.layers))
        if self.filled:
            self.collections = silent_list('PolyCollection')
        else:
            self.collections = silent_list('LineCollection')
        # label lists must be initialized here
        self.cl = []
        self.cl_cvalues = []

        kw = {'cmap': cmap}
        if norm is not None:
            kw['norm'] = norm
        ScalarMappable.__init__(self, **kw)  # sets self.cmap;
        self._process_colors()

        if self.filled:
            if self.linewidths is None:
                self.linewidths = 0.05  # Good default for Postscript.
            if iterable(self.linewidths):
                self.linewidths = self.linewidths[0]
            #C = _contour.Cntr(x, y, z.filled(), z.mask())
            C = _contour.Cntr(x, y, z.filled(), ma.getmaskorNone(z))
            lowers = self._levels[:-1]
            uppers = self._levels[1:]
            for level, level_upper, color in zip(lowers, uppers, self.tcolors):
                nlist = C.trace(level,
                                level_upper,
                                points=0,
                                nchunk=self.nchunk)
                col = PolyCollection(nlist,
                                     linewidths=(self.linewidths, ),
                                     antialiaseds=(self.antialiased, ),
                                     facecolors=color,
                                     edgecolors='None')
                self.ax.add_collection(col)
                self.collections.append(col)

        else:
            tlinewidths = self._process_linewidths()
            self.tlinewidths = tlinewidths
            #C = _contour.Cntr(x, y, z.filled(), z.mask())
            C = _contour.Cntr(x, y, z.filled(), ma.getmaskorNone(z))
            for level, color, width in zip(self.levels, self.tcolors,
                                           tlinewidths):
                nlist = C.trace(level, points=0)
                col = LineCollection(nlist, colors=color, linewidths=width)

                if level < 0.0 and self.monochrome:
                    col.set_linestyle(
                        (0, rcParams['contour.negative_linestyle']))
                col.set_label(str(level))  # only for self-documentation
                self.ax.add_collection(col)
                self.collections.append(col)
        x0 = ma.minimum(x)
        x1 = ma.maximum(x)
        y0 = ma.minimum(y)
        y1 = ma.maximum(y)
        self.ax.update_datalim([(x0, y0), (x1, y1)])
        self.ax.set_xlim((x0, x1))
        self.ax.set_ylim((y0, y1))
Beispiel #9
0
    def __init__(self, ax, *args, **kwargs):
        """
        Draw contour lines or filled regions, depending on
        whether keyword arg 'filled' is False (default) or True.

        The first argument of the initializer must be an axes
        object.  The remaining arguments and keyword arguments
        are described in ContourSet.contour_doc.

        """
        self.ax = ax
        self.filled = kwargs.get('filled', False)
        self.linewidths = kwargs.get('linewidths', None)

        self.alpha = kwargs.get('alpha', 1.0)
        self.origin = kwargs.get('origin', None)
        self.extent = kwargs.get('extent', None)
        cmap = kwargs.get('cmap', None)
        self.colors = kwargs.get('colors', None)
        self.clip_ends = kwargs.get('clip_ends', True)
        self.antialiased = kwargs.get('antialiased', True)
        self.nchunk = kwargs.get('nchunk', 0)

        if self.origin is not None: assert(self.origin in
                                            ['lower', 'upper', 'image'])
        if self.extent is not None: assert(len(self.extent) == 4)
        if cmap is not None: assert(isinstance(cmap, Colormap))
        if self.colors is not None and cmap is not None:
            raise ValueError('Either colors or cmap must be None')
        if self.origin == 'image': self.origin = rcParams['image.origin']
        x, y, z = self._contour_args(*args)        # also sets self.levels,
                                                   #  self.layers
        if self.colors is not None:
            cmap = ListedColormap(self.colors, N=len(self.layers))
        if self.filled:
            self.collections = silent_list('PolyCollection')
        else:
            self.collections = silent_list('LineCollection')
        # label lists must be initialized here
        self.cl = []
        self.cl_cvalues = []

        ScalarMappable.__init__(self, cmap = cmap) # sets self.cmap;
                                                   # default norm for now
        self._process_colors()


        if self.filled:
            if self.linewidths is None:
                self.linewidths = 0.05 # Good default for Postscript.
            if iterable(self.linewidths):
                self.linewidths = self.linewidths[0]
            #C = _contour.Cntr(x, y, z.filled(), z.mask())
            C = _contour.Cntr(x, y, z.filled(), ma.getmask(z))
            lowers = self.levels[:-1]
            uppers = self.levels[1:]
            for level, level_upper, color in zip(lowers, uppers, self.tcolors):
                nlist = C.trace(level, level_upper, points = 1,
                        nchunk = self.nchunk)
                col = PolyCollection(nlist,
                                     linewidths = (self.linewidths,),
                                     antialiaseds = (self.antialiased,))
                col.set_color(color) # sets both facecolor and edgecolor
                self.ax.add_collection(col)
                self.collections.append(col)

        else:
            tlinewidths = self._process_linewidths()
            #C = _contour.Cntr(x, y, z.filled(), z.mask())
            C = _contour.Cntr(x, y, z.filled(), ma.getmask(z))
            for level, color, width in zip(self.levels, self.tcolors, tlinewidths):
                nlist = C.trace(level, points = 1)
                col = LineCollection(nlist)
                col.set_color(color)
                col.set_linewidth(width)

                if level < 0.0 and self.monochrome:
                    col.set_linestyle((0, (6.,6.)),)
                    #print "setting dashed"
                col.set_label(str(level))         # only for self-documentation
                self.ax.add_collection(col)
                self.collections.append(col)

        ## check: seems like set_xlim should also be inside
        if not self.ax.ishold():
            self.ax.cla()
        self.ax.set_xlim((ma.minimum(x), ma.maximum(x)))
        self.ax.set_ylim((ma.minimum(y), ma.maximum(y)))
Beispiel #10
0
    def __init__(self, ax, *args, **kwargs):
        """
        Draw contour lines or filled regions, depending on
        whether keyword arg 'filled' is False (default) or True.

        The first argument of the initializer must be an axes
        object.  The remaining arguments and keyword arguments
        are described in ContourSet.contour_doc.

        """
        self.ax = ax
        self.levels = kwargs.get('levels', None)
        self.filled = kwargs.get('filled', False)
        self.linewidths = kwargs.get('linewidths', None)

        self.alpha = kwargs.get('alpha', 1.0)
        self.origin = kwargs.get('origin', None)
        self.extent = kwargs.get('extent', None)
        cmap = kwargs.get('cmap', None)
        self.colors = kwargs.get('colors', None)
        norm = kwargs.get('norm', None)
        self.clip_ends = kwargs.get('clip_ends', None)      ########
        self.extend = kwargs.get('extend', 'neither')
        if self.clip_ends is not None:
            warnings.warn("'clip_ends' has been replaced by 'extend'")
            self.levels = self.levels[1:-1] # discard specified end levels
            self.extend = 'both'            # regenerate end levels
        self.antialiased = kwargs.get('antialiased', True)
        self.nchunk = kwargs.get('nchunk', 0)
        self.locator = kwargs.get('locator', None)

        if self.origin is not None: assert(self.origin in
                                            ['lower', 'upper', 'image'])
        if self.extent is not None: assert(len(self.extent) == 4)
        if cmap is not None: assert(isinstance(cmap, Colormap))
        if self.colors is not None and cmap is not None:
            raise ValueError('Either colors or cmap must be None')
        if self.origin == 'image': self.origin = rcParams['image.origin']
        x, y, z = self._contour_args(*args)        # also sets self.levels,
                                                   #  self.layers
        if self.colors is not None:
            cmap = ListedColormap(self.colors, N=len(self.layers))
        if self.filled:
            self.collections = silent_list('PolyCollection')
        else:
            self.collections = silent_list('LineCollection')
        # label lists must be initialized here
        self.cl = []
        self.cl_cvalues = []

        kw = {'cmap': cmap}
        if norm is not None:
            kw['norm'] = norm
        ScalarMappable.__init__(self, **kw) # sets self.cmap;
        self._process_colors()

        if self.filled:
            if self.linewidths is None:
                self.linewidths = 0.05 # Good default for Postscript.
            if iterable(self.linewidths):
                self.linewidths = self.linewidths[0]
            #C = _contour.Cntr(x, y, z.filled(), z.mask())
            C = _contour.Cntr(x, y, z.filled(), ma.getmaskorNone(z))
            lowers = self._levels[:-1]
            uppers = self._levels[1:]
            for level, level_upper, color in zip(lowers, uppers, self.tcolors):
                nlist = C.trace(level, level_upper, points = 0,
                        nchunk = self.nchunk)
                col = PolyCollection(nlist,
                                     linewidths = (self.linewidths,),
                                     antialiaseds = (self.antialiased,),
                                     facecolors= color,
                                     edgecolors= 'None')
                self.ax.add_collection(col)
                self.collections.append(col)

        else:
            tlinewidths = self._process_linewidths()
            self.tlinewidths = tlinewidths
            #C = _contour.Cntr(x, y, z.filled(), z.mask())
            C = _contour.Cntr(x, y, z.filled(), ma.getmaskorNone(z))
            for level, color, width in zip(self.levels, self.tcolors, tlinewidths):
                nlist = C.trace(level, points = 0)
                col = LineCollection(nlist,
                                     colors = color,
                                     linewidths = width)

                if level < 0.0 and self.monochrome:
                    col.set_linestyle((0, rcParams['contour.negative_linestyle']))
                col.set_label(str(level))         # only for self-documentation
                self.ax.add_collection(col)
                self.collections.append(col)
        x0 = ma.minimum(x)
        x1 = ma.maximum(x)
        y0 = ma.minimum(y)
        y1 = ma.maximum(y)
        self.ax.update_datalim([(x0,y0), (x1,y1)])
        self.ax.set_xlim((x0, x1))
        self.ax.set_ylim((y0, y1))