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
| import numpy as np import pandas as pd import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D xs=np.arange(-5,5,0.2) ys1=np.sqrt(25-xs*xs)+np.random.uniform(-0.5,0.5,(xs.shape[0])) ys2=-1*np.sqrt(25-xs*xs)+np.random.uniform(-0.5,0.5,(xs.shape[0]))
xys1=np.c_[xs,ys1]
xys2=np.c_[xs,ys2]
xy1=np.r_[xys1,xys2]
xh=np.arange(-8,8,0.2) yh1=np.sqrt(64-xh*xh)+np.random.uniform(-0.5,0.5,(xh.shape[0])) yh2=-1*np.sqrt(64-xh*xh)+np.random.uniform(-0.5,0.5,(xh.shape[0]))
xyh1=np.c_[xh,yh1]
xyh2=np.c_[xh,yh2]
xy2=np.r_[xyh1,xyh2]
xy3=np.r_[xy1,xy2] plt.figure()
plt.scatter(xy3[0:100,0],xy3[0:100,1],c='k',marker='*') plt.scatter(xy3[100:,0],xy3[100:,1],c='r',marker='o')
fig=plt.figure() ax=Axes3D(fig)
z1=xy3[:,0]**2 z2=xy3[:,1]**2 z3=xy3[:,1] ax.scatter(z1[0:100],z2[0:100],z3[0:100],c='k',marker='*') ax.scatter(z1[100:],z2[100:],z3[100:],c='r',marker='o')
plt.show()
|