Skip to content Skip to sidebar Skip to footer

Matplotlib Plot_surface Plot

The matplotlib tutorial provides a nice example of how to draw a spherical suface: from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig =

Solution 1:

The Equation of a surface is:

  f(x,y,z)=c

where the constants characterize the surfaces. In the case of a circle it is:

(x^2 + y^2 + z^2)^(1/2) = c

Where c is the radius. each value of gives one surface. In other words, f(x,y,z) can be written as z=g(x,y). Now if you have to span an area with two independent variables x & y, both will have to be 2D arrays. note that both x and y will be 2D arrays and so will z.


Solution 2:

A: Because the interface specification orders that.

However strange does that look, the 2D-parametric grid,

describing the surface [ R = const, u = < 0, 2pi >, v = < 0, pi > ] from Spherical coordinate space is translated into a cartesian-space via a mapping,

stored in a set of [ MAT2Dx[,], MAT2Dy[,], MAT2Dz[,] ]

because that is the requirement the .plot_surface() method requires the surface-data to be received.

>>> print ax.plot_surface.__doc__

        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*, *Z* Data values as 2D arrays
        *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
        ============= ================================================

        Other arguments are passed on to
        :class:`~mpl_toolkits.mplot3d.art3d.Poly3DCollection`

By design, a surface is a 2D-entity, here parametrised either by in [R,u,v] or [X,Y,Z] coordinate system, and due to the ease of [R,u,v] analytic description of a sphere surface, the meshing started in [u,v]-grid produced by a pair of .linspace() methods, whereas remained R=const=10.

Further:

>>> print np.outer.__doc__

    Compute the outer product of two vectors.

    Given two vectors, ``a = [a0, a1, ..., aM]`` and
    ``b = [b0, b1, ..., bN]``,
    the outer product [1]_ is::

      [[a0*b0  a0*b1 ... a0*bN ]
       [a1*b0    .
       [ ...          .
       [aM*b0            aM*bN ]]

has created x, y, z matrices in a shape of [100,100], as a trigonometry-laws-based mapping of [u,v] -> x(u,v), y(u,v), z(u,v)

finally, .plot_surface() method has consumed these in

 x,y,z = np.broadcast_matrices( x, y, z )

before starting to produce a list of 2D-surface-objects ( to be plot ), iterating over the scope of the original [u,v]-2Dgrid.


Post a Comment for "Matplotlib Plot_surface Plot"