lib/mpl_toolkits/mplot3d/axes3d.py
def plot_surface(self, X, Y, Z, *args, **kwargs):
        '''
        Create a surface plot.

        By default it will be colored in shades of a solid color,
        but it also supports color mapping by supplying the *cmap*
        argument.

        ==========  ================================================
        Argument    Description
        ==========  ================================================
        *X*, *Y*,   Data values as numpy.arrays
        *Z*
        *rstride*   Array row stride (step size)
        *cstride*   Array column stride (step size)
        *color*     Color of the surface patches
        *cmap*      A colormap for the surface patches.
        *facecolors* Face colors for the individual patches
        *norm*      An instance of Normalize to map values to colors
        *vmin*      Minimum value to map
        *vmax*      Maximum value to map
        *shade*     Whether to shade the facecolors, default:
                    false when cmap specified, true otherwise
        ==========  ================================================
        '''

        had_data = self.has_data()

        rows, cols = Z.shape
        tX, tY, tZ = np.transpose(X), np.transpose(Y), np.transpose(Z)
        rstride = kwargs.pop('rstride', 10)
        cstride = kwargs.pop('cstride', 10)

        if 'facecolors' in kwargs:
            fcolors = kwargs.pop('facecolors')
        else:
            color = np.array(colorConverter.to_rgba(kwargs.pop('color', 'b')))
            fcolors = None

        cmap = kwargs.get('cmap', None)
        norm = kwargs.pop('norm', None)
        vmin = kwargs.pop('vmin', None)
        vmax = kwargs.pop('vmax', None)
        linewidth = kwargs.get('linewidth', None)
        shade = kwargs.pop('shade', cmap is None)
        lightsource = kwargs.pop('lightsource', None)

        # Shade the data
        if shade and cmap is not None and fcolors is not None:
            fcolors = self._shade_colors_lightsource(Z, cmap, lightsource)

        polys = []
        normals = []
        #colset contains the data for coloring: either average z or the facecolor
        colset = []
        for rs in np.arange(0, rows-1, rstride):
            for cs in np.arange(0, cols-1, cstride):
                ps = []
                corners = []
                for a, ta in [(X, tX), (Y, tY), (Z, tZ)]:
                    ztop = a[rs][cs:min(cols, cs+cstride+1)]
                    zleft = ta[min(cols-1, cs+cstride)][rs:min(rows, rs+rstride+1)]
                    zbase = a[min(rows-1, rs+rstride)][cs:min(cols, cs+cstride+1):]
                    zbase = zbase[::-1]
                    zright = ta[cs][rs:min(rows, rs+rstride+1):]
                    zright = zright[::-1]
                    corners.append([ztop[0], ztop[-1], zbase[0], zbase[-1]])
                    z = np.concatenate((ztop, zleft, zbase, zright))
                    ps.append(z)

                # The construction leaves the array with duplicate points, which
                # are removed here.
                ps = zip(*ps)
                lastp = np.array([])
                ps2 = []
                avgzsum = 0.0
                for p in ps:
                    if p != lastp:
                        ps2.append(p)
                        lastp = p
                        avgzsum += p[2]
                polys.append(ps2)

                if fcolors is not None:
                    colset.append(fcolors[rs][cs])
                else:
                    colset.append(avgzsum / len(ps2))

                # Only need vectors to shade if no cmap
                if cmap is None and shade:
                    v1 = np.array(ps2[0]) - np.array(ps2[1])
                    v2 = np.array(ps2[2]) - np.array(ps2[0])
                    normals.append(np.cross(v1, v2))

        polyc = art3d.Poly3DCollection(polys, *args, **kwargs)

        if fcolors is not None:
            if shade:
                colset = self._shade_colors(colset, normals)
            polyc.set_facecolors(colset)
            polyc.set_edgecolors(colset)
        elif cmap:
            colset = np.array(colset)
            polyc.set_array(colset)
            if vmin is not None or vmax is not None:
                polyc.set_clim(vmin, vmax)
            if norm is not None:
                polyc.set_norm(norm)
        else:
            if shade:
                colset = self._shade_colors(color, normals)
            else:
                colset = color
            polyc.set_facecolors(colset)

        self.add_collection(polyc)
        self.auto_scale_xyz(X, Y, Z, had_data)

        return polyc

        Create a surface plot.

        By default it will be colored in shades of a solid color,
        but it also supports color mapping by supplying the *cmap*
        argument.

        ==========  ================================================
        Argument    Description
        ==========  ================================================
        *X*, *Y*,   Data values as numpy.arrays
        *Z*
        *rstride*   Array row stride (step size)
        *cstride*   Array column stride (step size)
        *color*     Color of the surface patches
        *cmap*      A colormap for the surface patches.
        *facecolors* Face colors for the individual patches
        *norm*      An instance of Normalize to map values to colors
        *vmin*      Minimum value to map
        *vmax*      Maximum value to map
        *shade*     Whether to shade the facecolors, default:
                    false when cmap specified, true otherwise
        ==========  ================================================
        
Create a surface plot.
By default it will be colored in shades of a solid color,
but it also supports color mapping by supplying the *cmap
argument.

Argument    Description


Create a surface plot . By default it will be colored in shades of a solid color but it also supports color mapping by supplying the * cmap argument . Argument Description
def plot_surface(self, X, Y, Z, *args, **kwargs):
        had_data = self.has_data()
        rows, cols = Z.shape
        tX, tY, tZ = np.transpose(X), np.transpose(Y), np.transpose(Z)
        rstride = kwargs.pop('rstride', 10)
        cstride = kwargs.pop('cstride', 10)
        if 'facecolors' in kwargs:
            fcolors = kwargs.pop('facecolors')
        else:
            color = np.array(colorConverter.to_rgba(kwargs.pop('color', 'b')))
            fcolors = None
        cmap = kwargs.get('cmap', None)
        norm = kwargs.pop('norm', None)
        vmin = kwargs.pop('vmin', None)
        vmax = kwargs.pop('vmax', None)
        linewidth = kwargs.get('linewidth', None)
        shade = kwargs.pop('shade', cmap is None)
        lightsource = kwargs.pop('lightsource', None)
        if shade and cmap is not None and fcolors is not None:
            fcolors = self._shade_colors_lightsource(Z, cmap, lightsource)
        polys = []
        normals = []
        colset = []
        for rs in np.arange(0, rows-1, rstride):
            for cs in np.arange(0, cols-1, cstride):
                ps = []
                corners = []
                for a, ta in [(X, tX), (Y, tY), (Z, tZ)]:
                    ztop = a[rs][cs:min(cols, cs+cstride+1)]
                    zleft = ta[min(cols-1, cs+cstride)][rs:min(rows, rs+rstride+1)]
                    zbase = a[min(rows-1, rs+rstride)][cs:min(cols, cs+cstride+1):]
                    zbase = zbase[::-1]
                    zright = ta[cs][rs:min(rows, rs+rstride+1):]
                    zright = zright[::-1]
                    corners.append([ztop[0], ztop[-1], zbase[0], zbase[-1]])
                    z = np.concatenate((ztop, zleft, zbase, zright))
                    ps.append(z)
                ps = zip(*ps)
                lastp = np.array([])
                ps2 = []
                avgzsum = 0.0
                for p in ps:
                    if p != lastp:
                        ps2.append(p)
                        lastp = p
                        avgzsum += p[2]
                polys.append(ps2)
                if fcolors is not None:
                    colset.append(fcolors[rs][cs])
                else:
                    colset.append(avgzsum / len(ps2))
                if cmap is None and shade:
                    v1 = np.array(ps2[0]) - np.array(ps2[1])
                    v2 = np.array(ps2[2]) - np.array(ps2[0])
                    normals.append(np.cross(v1, v2))
        polyc = art3d.Poly3DCollection(polys, *args, **kwargs)
        if fcolors is not None:
            if shade:
                colset = self._shade_colors(colset, normals)
            polyc.set_facecolors(colset)
            polyc.set_edgecolors(colset)
        elif cmap:
            colset = np.array(colset)
            polyc.set_array(colset)
            if vmin is not None or vmax is not None:
                polyc.set_clim(vmin, vmax)
            if norm is not None:
                polyc.set_norm(norm)
        else:
            if shade:
                colset = self._shade_colors(color, normals)
            else:
                colset = color
            polyc.set_facecolors(colset)
        self.add_collection(polyc)
        self.auto_scale_xyz(X, Y, Z, had_data)
        return polyc
def plot_surface ( self , X , Y , Z , * args , ** kwargs ) : had_data = self . has_data ( ) rows , cols = Z . shape tX , tY , tZ = np . transpose ( X ) , np . transpose ( Y ) , np . transpose ( Z ) rstride = kwargs . pop ( 'rstride' , 10 ) cstride = kwargs . pop ( 'cstride' , 10 ) if 'facecolors' in kwargs : fcolors = kwargs . pop ( 'facecolors' ) else : color = np . array ( colorConverter . to_rgba ( kwargs . pop ( 'color' , 'b' ) ) ) fcolors = None cmap = kwargs . get ( 'cmap' , None ) norm = kwargs . pop ( 'norm' , None ) vmin = kwargs . pop ( 'vmin' , None ) vmax = kwargs . pop ( 'vmax' , None ) linewidth = kwargs . get ( 'linewidth' , None ) shade = kwargs . pop ( 'shade' , cmap is None ) lightsource = kwargs . pop ( 'lightsource' , None ) if shade and cmap is not None and fcolors is not None : fcolors = self . _shade_colors_lightsource ( Z , cmap , lightsource ) polys = [ ] normals = [ ] colset = [ ] for rs in np . arange ( 0 , rows - 1 , rstride ) : for cs in np . arange ( 0 , cols - 1 , cstride ) : ps = [ ] corners = [ ] for a , ta in [ ( X , tX ) , ( Y , tY ) , ( Z , tZ ) ] : ztop = a [ rs ] [ cs : min ( cols , cs + cstride + 1 ) ] zleft = ta [ min ( cols - 1 , cs + cstride ) ] [ rs : min ( rows , rs + rstride + 1 ) ] zbase = a [ min ( rows - 1 , rs + rstride ) ] [ cs : min ( cols , cs + cstride + 1 ) : ] zbase = zbase [ : : - 1 ] zright = ta [ cs ] [ rs : min ( rows , rs + rstride + 1 ) : ] zright = zright [ : : - 1 ] corners . append ( [ ztop [ 0 ] , ztop [ - 1 ] , zbase [ 0 ] , zbase [ - 1 ] ] ) z = np . concatenate ( ( ztop , zleft , zbase , zright ) ) ps . append ( z ) ps = zip ( * ps ) lastp = np . array ( [ ] ) ps2 = [ ] avgzsum = 0.0 for p in ps : if p != lastp : ps2 . append ( p ) lastp = p avgzsum += p [ 2 ] polys . append ( ps2 ) if fcolors is not None : colset . append ( fcolors [ rs ] [ cs ] ) else : colset . append ( avgzsum / len ( ps2 ) ) if cmap is None and shade : v1 = np . array ( ps2 [ 0 ] ) - np . array ( ps2 [ 1 ] ) v2 = np . array ( ps2 [ 2 ] ) - np . array ( ps2 [ 0 ] ) normals . append ( np . cross ( v1 , v2 ) ) polyc = art3d . Poly3DCollection ( polys , * args , ** kwargs ) if fcolors is not None : if shade : colset = self . _shade_colors ( colset , normals ) polyc . set_facecolors ( colset ) polyc . set_edgecolors ( colset ) elif cmap : colset = np . array ( colset ) polyc . set_array ( colset ) if vmin is not None or vmax is not None : polyc . set_clim ( vmin , vmax ) if norm is not None : polyc . set_norm ( norm ) else : if shade : colset = self . _shade_colors ( color , normals ) else : colset = color polyc . set_facecolors ( colset ) self . add_collection ( polyc ) self . auto_scale_xyz ( X , Y , Z , had_data ) return polyc
Create a surface plot.
Create a surface plot .
'''
        Create a surface plot.

        By default it will be colored in shades of a solid color,
        but it also supports color mapping by supplying the *cmap*
        argument.

        ==========  ================================================
        Argument    Description
        ==========  ================================================
        *X*, *Y*,   Data values as numpy.arrays
        *Z*
        *rstride*   Array row stride (step size)
        *cstride*   Array column stride (step size)
        *color*     Color of the surface patches
        *cmap*      A colormap for the surface patches.
        *facecolors* Face colors for the individual patches
        *norm*      An instance of Normalize to map values to colors
        *vmin*      Minimum value to map
        *vmax*      Maximum value to map
        *shade*     Whether to shade the facecolors, default:
                    false when cmap specified, true otherwise
        ==========  ================================================
        ''' # Shade the data #colset contains the data for coloring: either average z or the facecolor # The construction leaves the array with duplicate points, which # are removed here. # Only need vectors to shade if no cmap
self
X
Y
Z