Python uses matplotlib to draw 3D graphics, pythonmatplotlib
This example describes how to use matplotlib to draw 3D images in Python. We will share this with you for your reference. The details are as follows:
Code 1:
# Coding = utf-8import numpy as npimport matplotlib. pyplot as pltimport mpl_toolkits.mplot3dx, y = np. mgrid [-2: 2: 20j,-2: 2: 20j] # Test Data z = x * np. exp (-x ** 2-y ** 2) # 3D image ax = plt. subplot (111, projection = '3d ') ax. set_title ('www .jb51.net-matplotlib demo'); ax. plot_surface (x, y, z, rstride = 2, cstride = 1, cmap = plt. cm. blues_r) # Set the axis label ax. set_xlabel ('x') ax. set_ylabel ('y') ax. set_zlabel ('Z') plt. show ()
Running result:
Code 2:
# Coding = utf-8import pylab as plimport numpy as npimport mpl_toolkits.mplot3drho, theta = np. mgrid [0: 1: 40j, 0: 2 * np. pi: 40j] z = company ** 2x = company * np. cos (theta) y = company * np. sin (theta) ax = pl. subplot (111, projection = '3d ') ax. set_title ('www .jb51.net-matplotlib demo'); # ax. plot_surface (x, y, z) ax. plot_surface (x, y, z, rstride = 2, cstride = 1) # Set the axis label ax. set_xlabel ('x') ax. set_ylabel ('y') ax. set_zlabel ('Z') pl. show ()
Running result: