【发布时间】:2017-06-24 11:02:46
【问题描述】:
我在 Python (np) 中有一个 numpy 对象,我用它在 pyplot 中绘制图表。
这是一个 3D 图表,其中x、y 和z 是包含要绘制图表的值的列表。
下面是我的代码(来自here):
data = np.c_[x,y,z]
# regular grid covering the domain of the data
mn = np.min(data, axis=0) - 0.009
mx = np.max(data, axis=0) + 0.009
X,Y = np.meshgrid(np.linspace(mn[0], mx[0]), np.linspace(mn[1], mx[1]))
XX = X.flatten()
YY = Y.flatten()
A = np.c_[np.ones(data.shape[0]), data[:, :2], np.prod(data[:, :2], axis=1), data[:, :2] ** 2]
C, _, _, _ = scipy.linalg.lstsq(A, data[:, 2])
# evaluate it on a grid
Z = np.dot(np.c_[np.ones(XX.shape), XX, YY, XX * YY, XX ** 2, YY ** 2], C).reshape(X.shape)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, alpha=0.2)
ax.scatter(data[:, 0], data[:, 1], data[:, 2], c='r', s=50)
plt.xlabel('X')
plt.ylabel('Y')
ax.set_zlabel('Z')
ax.axis('equal')
ax.axis('tight')
plt.show()
所以在这里,我想获取x 和y 的值,其中z 的值最接近-30。如何获得x 和y 的值。
【问题讨论】:
-
如果我理解你的问题是正确的,这可能会有所帮助stackoverflow.com/questions/2566412/…
标签: python numpy matplotlib graph regression