Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > bf21b4394f4d7fa09e3626145d3315e0 > files > 256

python-matplotlib-doc-1.2.0-14.fc18.i686.rpm

.. _mplot3d-trisurf3d_demo:

mplot3d example code: trisurf3d_demo.py
=======================================



.. plot:: /builddir/build/BUILD/matplotlib-1.2.0/doc/mpl_examples/mplot3d/trisurf3d_demo.py

::

    from mpl_toolkits.mplot3d import Axes3D
    from matplotlib import cm
    import matplotlib.pyplot as plt
    import numpy as np
    
    n_angles = 36
    n_radii = 8
    
    # An array of radii
    # Does not include radius r=0, this is to eliminate duplicate points
    radii = np.linspace(0.125, 1.0, n_radii)
    
    # An array of angles
    angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
    
    # Repeat all angles for each radius
    angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)
    
    # Convert polar (radii, angles) coords to cartesian (x, y) coords
    # (0, 0) is added here. There are no duplicate points in the (x, y) plane
    x = np.append(0, (radii*np.cos(angles)).flatten())
    y = np.append(0, (radii*np.sin(angles)).flatten())
    
    # Pringle surface
    z = np.sin(-x*y)
    
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    
    ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2)
    
    plt.show()
    

Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)