Making 3D plots

There are some useful matplotlib tool kits and modules that can be used for a variety of special purposes. In this section, we describe a method for producing 3D-plots.

The mplot3d toolkit provides 3D plotting of points, lines, contours, surfaces, and all other basic components as well as 3D rotation and scaling. Making a 3D plot is done by adding the keyword projection='3d' to the axes object as shown in the following example:

from mpl_toolkits.mplot3d import axes3d fig = figure() ax = fig.gca(projection='3d') # plot points in 3D class1 = 0.6 * random.standard_normal((200,3)) ax.plot(class1[:,0],class1[:,1],class1[:,2],'o') class2 = 1.2 * random.standard_normal((200,3)) + array([5,4,0]) ax.plot(class2[:,0],class2[:,1],class2[:,2],'o') ...

Get Scientific Computing with Python 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.