Matplotlib: 3-D mesh wiregrid example

Note: You can also use Mayavi for advanced 3-D plotting in Python

3-D mesh wiregrid: minimal working example for the current version of Matplotlib:

#!/usr/bin/env python
from mpl_toolkits.mplot3d import Axes3D # this line must come before the next line!
from matplotlib.pyplot import figure,show
from numpy import linspace,meshgrid,pi,sin #for testing
key point: the line "from mpl_toolkits.mplot3d import Axes3D" needs to come before
the "from matplotlib.pyplot import ...." line in the FIRST file you run.
To be sure, I make the "from mpl_toolkits.mplot3d ..." line come first in my
main function file (the one I invoke from the command line or Spyder)

def test():
    x,y = meshgrid(linspace(0,2*pi),linspace(0,2*pi))

    z = sin(x+0.5*y)
    ax = figure().gca(projection='3d')

if __name__ == '__main__':

Leave a Comment