1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| import matplotlib.pyplot as plt import numpy as np
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(20,10))
axl = fig.add_subplot(221,projection='3d') theta = np.linspace(-4*np.pi, 4*np.pi, 500) z = np.linspace(-2,2,500) r = z**2 + 1 x = r*np.sin(theta) y = r*np.conj(theta)
axl.plot(x,y,z) axl.set_xlabel('x', fontsize=15) axl.set_ylabel('y', fontsize=15) axl.set_zlabel('z', fontsize=15)
axl2 = fig.add_subplot(222,projection='3d')
x = np.random.randn(500) y = np.random.randn(500) z = np.random.randn(500)
axl2.scatter(x,y,z,c='r') axl2.set_xlabel('x', fontsize=15) axl2.set_ylabel('y', fontsize=15) axl2.set_zlabel('z',fontsize=15)
axl3 = fig.add_subplot(223,projection='3d') x = np.linspace(-2,2,500) y = np.linspace(-2,2,500) x,y = np.meshgrid(x,y) z = np.sqrt(x**2 + y**2) axl3.plot_surface(x,y,z,cmap=plt.cm.winter) axl3.set_xlabel('x', fontsize=15) axl3.set_ylabel('y', fontsize=15) axl3.set_zlabel('z', fontsize=15)
axl4 = fig.add_subplot(224, projection='3d') for z in np.arange(0,40,10): x = np.arange(20) y = np.random.randn(20) axl4.bar(x,y,zs=z,zdir='y')
axl4.set_xlabel('x',fontsize=15) axl4.set_ylabel('y',fontsize=15) axl4.set_zlabel('z',fontsize=15)
plt.show()
|