我无法将多组数据绘制到单个 3D 散点图上。我正在做的是我有一个由三个方程组成的系统,我正在使用 linalg 计算方程的零点。然后,我将得到的每组零绘制到 3D 图上。对于我的一个参数,我正在更改它的值并观察零点如何变化。我想将所有数据集绘制在一个 3D 散点图上,以便比较它们的不同之处,但我不断为每个数据集绘制一个图表。你们中的任何人都可以弄清楚我需要解决什么问题吗?
import numpy as np
from numpy import linalg
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
plt.close('all')
#Will be solving the following system of equations:
#sx-(b/r)z=0
#-x+ry+(s-b)z=0
#(1/r)x+y-z=0
r=50.0
b=17.0/4.0
s=[10.0,20.0,7.0,r/b]
color=['r','b','g','y']
markers=['s','o','^','d']
def system(s,b,r,color,m):
#first creates the matrix as an array so the parameters can be changed from outside
#and then coverts array into a matrix
u_arr=np.array([[s,0,-b/r],[-1,r,s-b],[1/r,1,-1]])
u_mat=np.matrix(u_arr)
U_mat=linalg.inv(u_mat)
#converts matrix into an array and then into a list to manipulate
x_zeros=np.array(U_mat[0]).reshape(-1).tolist()
y_zeros=np.array(U_mat[1]).reshape(-1).tolist()
z_zeros=np.array(U_mat[2]).reshape(-1).tolist()
zeros=[x_zeros,y_zeros,z_zeros]
coordinates=['x','y','z']
print('+'*70)
print('For s=%1.1f:' % s)
print('\n')
for i in range(3):
print('For the %s direction, the roots are: ' % coordinates[i])
for j in range(3):
print(zeros[i][j])
print('-'*50)
fig3d=plt.figure()
ax=Axes3D(fig3d)
ax.scatter(x_zeros,y_zeros,z_zeros,c=color,marker=m)
plt.title('Zeros for a Given System of Equations for s=%1.1f' % (s))
ax.set_xlabel('Zeros in x Direction')
ax.set_ylabel('Zeros in y Direction')
ax.set_zlabel('Zeros in z Direction')
plt.show()
for k in range(len(s)):
system(s[k],b,r,color[k],markers[k])
提前感谢您的帮助。