Exemple #1
0
    def set_data(self, *args):
        """
        Set the x and y data

        ACCEPTS: (npy.array xdata, npy.array ydata)
        """
        if len(args)==1:
            x, y = args[0]
        else:
            x, y = args

        not_masked = 0
        if not ma.isMaskedArray(x):
            x = npy.asarray(x)
            not_masked += 1
        if not ma.isMaskedArray(y):
            y = npy.asarray(y)
            not_masked += 1

        if (not_masked < 2 or
            (x is not self._xorig and
             (x.shape != self._xorig.shape or npy.any(x != self._xorig))) or
            (y is not self._yorig and
              (y.shape != self._yorig.shape or npy.any(y != self._yorig)))):
            self._xorig = x
            self._yorig = y
            self._invalid = True
Exemple #2
0
    def __init__(self, vertices, codes=None):
        """
        Create a new path with the given vertices and codes.

        vertices is an Nx2 numpy float array, masked array or Python
        sequence.

        codes is an N-length numpy array or Python sequence of type
        Path.code_type.

        See the docstring of Path for a description of the various
        codes.

        These two arrays must have the same length in the first
        dimension.

        If codes is None, vertices will be treated as a series of line
        segments.  If vertices contains masked values, the resulting
        path will be compressed, with MOVETO codes inserted in the
        correct places to jump over the masked regions.
        """
        if ma.isMaskedArray(vertices):
            mask = ma.getmask(vertices)
        else:
            vertices = npy.asarray(vertices, npy.float_)
            mask = ma.nomask

        if codes is not None:
	    codes = npy.asarray(codes, self.code_type)
            assert codes.ndim == 1
            assert len(codes) == len(vertices)

        # The path being passed in may have masked values.  However,
        # the backends (and any affine transformations in matplotlib
        # itself), are not expected to deal with masked arrays, so we
        # must remove them from the array (using compressed), and add
        # MOVETO commands to the codes array accordingly.
        if mask is not ma.nomask:
            mask1d = ma.mask_or(mask[:, 0], mask[:, 1])
            if codes is None:
                codes = self.LINETO * npy.ones(
                    len(vertices), self.code_type)
                codes[0] = self.MOVETO
            vertices = ma.compress(npy.invert(mask1d), vertices, 0)
            codes = npy.where(npy.concatenate((mask1d[-1:], mask1d[:-1])),
                              self.MOVETO, codes)
            codes = ma.masked_array(codes, mask=mask1d).compressed()
            codes = npy.asarray(codes, self.code_type)

        assert vertices.ndim == 2
        assert vertices.shape[1] == 2

        self.codes = codes
	self.vertices = vertices
Exemple #3
0
    def recache(self):
        #if self.axes is None: print 'recache no axes'
        #else: print 'recache units', self.axes.xaxis.units, self.axes.yaxis.units
        if ma.isMaskedArray(self._xorig) or ma.isMaskedArray(self._yorig):
            x = ma.asarray(self.convert_xunits(self._xorig), float)
            y = ma.asarray(self.convert_yunits(self._yorig), float)
            x = ma.ravel(x)
            y = ma.ravel(y)
        else:
            x = npy.asarray(self.convert_xunits(self._xorig), float)
            y = npy.asarray(self.convert_yunits(self._yorig), float)
            x = npy.ravel(x)
            y = npy.ravel(y)

        if len(x)==1 and len(y)>1:
            x = x * npy.ones(y.shape, float)
        if len(y)==1 and len(x)>1:
            y = y * npy.ones(x.shape, float)

        if len(x) != len(y):
            raise RuntimeError('xdata and ydata must be the same length')

        x = x.reshape((len(x), 1))
        y = y.reshape((len(y), 1))

        if ma.isMaskedArray(x) or ma.isMaskedArray(y):
            self._xy = ma.concatenate((x, y), 1)
        else:
            self._xy = npy.concatenate((x, y), 1)
	self._x = self._xy[:, 0] # just a view
	self._y = self._xy[:, 1] # just a view

        # Masked arrays are now handled by the Path class itself
        self._path = Path(self._xy)
        self._transformed_path = TransformedPath(self._path, self.get_transform())

        self._invalid = False