Example #1
0
 def scatter(self, xs, ys, zs=0, zdir='z', *args, **kwargs):
     '''
     Create a scatter plot.
     ==========  ================================================
     Argument    Description
     ==========  ================================================
     *xs*, *ys*  Positions of data points.
     *zs*        Either an array of the same length as *xs* and
                 *ys* or a single value to place all points in
                 the same plane. Default is 0.
     *zdir*      Which direction to use as z ('x', 'y' or 'z')
                 when plotting a 2d set.
     ==========  ================================================
     Keyword arguments are passed on to
     :func:`~matplotlib.axes.Axes.scatter`.
     Returns a :class:`~mpl_toolkits.mplot3d.art3d.Patch3DCollection`
     '''
     had_data = self.has_data()
     patches = Axes.scatter(self, xs, ys, *args, **kwargs)
     if not cbook.iterable(zs):
         is_2d = True
         zs = np.ones(len(xs)) * zs
     else:
         is_2d = False
     art3d.patch_collection_2d_to_3d(patches, zs=zs, zdir=zdir)
     if not is_2d:
         self.auto_scale_xyz(xs, ys, zs, had_data)
     return patches
Example #2
0
    def add_collection3d(self, col, zs=0, zdir='z'):
        '''
        Add a 3d collection object to the plot.

        2D collection types are converted to a 3D version by
        modifying the object and adding z coordinate information.

        Supported are:
            - PolyCollection
            - LineColleciton
            - PatchCollection
        '''
        zvals = np.atleast_1d(zs)
        if len(zvals) > 0 :
            zsortval = min(zvals)
        else :
            zsortval = 0   # FIXME: Fairly arbitrary. Is there a better value?

        if type(col) is collections.PolyCollection:
            art3d.poly_collection_2d_to_3d(col, zs=zs, zdir=zdir)
            col.set_sort_zpos(zsortval)
        elif type(col) is collections.LineCollection:
            art3d.line_collection_2d_to_3d(col, zs=zs, zdir=zdir)
            col.set_sort_zpos(zsortval)
        elif type(col) is collections.PatchCollection:
            art3d.patch_collection_2d_to_3d(col, zs=zs, zdir=zdir)
            col.set_sort_zpos(zsortval)

        Axes.add_collection(self, col)
Example #3
0
 def add_collection3d(self, col, zs=0, zdir='z'):
     '''
     Add a 3d collection object to the plot.
     2D collection types are converted to a 3D version by
     modifying the object and adding z coordinate information.
     Supported are:
         - PolyCollection
         - LineColleciton
         - PatchCollection
     '''
     if type(col) is collections.PolyCollection:
         art3d.poly_collection_2d_to_3d(col, zs=zs, zdir=zdir)
         col.set_sort_zpos(min(zs))
     elif type(col) is collections.LineCollection:
         art3d.line_collection_2d_to_3d(col, zs=zs, zdir=zdir)
         col.set_sort_zpos(min(zs))
     elif type(col) is collections.PatchCollection:
         art3d.patch_collection_2d_to_3d(col, zs=zs, zdir=zdir)
         col.set_sort_zpos(min(zs))
     Axes.add_collection(self, col)
Example #4
0
    def add_collection3d(self, col, zs=0, zdir='z'):
        '''
        Add a 3d collection object to the plot.

        2D collection types are converted to a 3D version by
        modifying the object and adding z coordinate information.

        Supported are:
            - PolyCollection
            - LineColleciton
            - PatchCollection
        '''

        if type(col) is collections.PolyCollection:
            art3d.poly_collection_2d_to_3d(col, zs=zs, zdir=zdir)
            col.set_sort_zpos(min(zs))
        elif type(col) is collections.LineCollection:
            art3d.line_collection_2d_to_3d(col, zs=zs, zdir=zdir)
            col.set_sort_zpos(min(zs))
        elif type(col) is collections.PatchCollection:
            art3d.patch_collection_2d_to_3d(col, zs=zs, zdir=zdir)
            col.set_sort_zpos(min(zs))

        Axes.add_collection(self, col)
Example #5
0
    def scatter(self, xs, ys, zs=0, zdir='z', *args, **kwargs):
        '''
        Create a scatter plot.

        ==========  ================================================
        Argument    Description
        ==========  ================================================
        *xs*, *ys*  Positions of data points.
        *zs*        Either an array of the same length as *xs* and
                    *ys* or a single value to place all points in
                    the same plane. Default is 0.
        *zdir*      Which direction to use as z ('x', 'y' or 'z')
                    when plotting a 2d set.
        ==========  ================================================

        Keyword arguments are passed on to
        :func:`~matplotlib.axes.Axes.scatter`.

        Returns a :class:`~mpl_toolkits.mplot3d.art3d.Patch3DCollection`
        '''

        had_data = self.has_data()

        patches = Axes.scatter(self, xs, ys, *args, **kwargs)
        if not cbook.iterable(zs):
            is_2d = True
            zs = np.ones(len(xs)) * zs
        else:
            is_2d = False
        art3d.patch_collection_2d_to_3d(patches, zs=zs, zdir=zdir)

        #FIXME: why is this necessary?
        if not is_2d:
            self.auto_scale_xyz(xs, ys, zs, had_data)

        return patches
Example #6
0
    def scatter(self, xs, ys, zs=0, zdir='z', s=20, c='b', *args, **kwargs):
        '''
        Create a scatter plot.

        ==========  ==========================================================
        Argument    Description
        ==========  ==========================================================
        *xs*, *ys*  Positions of data points.
        *zs*        Either an array of the same length as *xs* and
                    *ys* or a single value to place all points in
                    the same plane. Default is 0.
        *zdir*      Which direction to use as z ('x', 'y' or 'z')
                    when plotting a 2d set.
        *s*         size in points^2.  It is a scalar or an array of the same
                    length as *x* and *y*.

        *c*         a color. *c* can be a single color format string, or a
                    sequence of color specifications of length *N*, or a
                    sequence of *N* numbers to be mapped to colors using the
                    *cmap* and *norm* specified via kwargs (see below). Note
                    that *c* should not be a single numeric RGB or RGBA
                    sequence because that is indistinguishable from an array
                    of values to be colormapped.  *c* can be a 2-D array in
                    which the rows are RGB or RGBA, however.
        ==========  ==========================================================

        Keyword arguments are passed on to
        :func:`~matplotlib.axes.Axes.scatter`.

        Returns a :class:`~mpl_toolkits.mplot3d.art3d.Patch3DCollection`
        '''

        had_data = self.has_data()

        xs = np.ma.ravel(xs)
        ys = np.ma.ravel(ys)
        zs = np.ma.ravel(zs)
        if xs.size != ys.size:
            raise ValueError("x and y must be the same size")
        if xs.size != zs.size and zs.size == 1:
            zs = np.array(zs[0] * xs.size)

        s = np.ma.ravel(s)  # This doesn't have to match x, y in size.

        cstr = cbook.is_string_like(c) or cbook.is_sequence_of_strings(c)
        if not cstr:
            c = np.asanyarray(c)
            if c.size == xs.size:
                c = np.ma.ravel(c)

        xs, ys, zs, s, c = cbook.delete_masked_points(xs, ys, zs, s, c)

        patches = Axes.scatter(self, xs, ys, s=s, c=c, *args, **kwargs)
        if not cbook.iterable(zs):
            is_2d = True
            zs = np.ones(len(xs)) * zs
        else:
            is_2d = False
        art3d.patch_collection_2d_to_3d(patches, zs=zs, zdir=zdir)

        #FIXME: why is this necessary?
        if not is_2d:
            self.auto_scale_xyz(xs, ys, zs, had_data)

        return patches