如何在3D空间呈现x^2+y^2
2个回答
你可以用颜色表示$f(x,y)$,比如下面的图
代码:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-3, 3, 101)
y = np.linspace(-3, 3, 101)
z = np.array([i*i+j*j for j in y for i in x])
X, Y = np.meshgrid(x, y)
Z = z.reshape(101, 101)
plt.figure(figsize=(5, 5))
plt.axis('equal')
plt.contourf(X, Y, Z, 50, cmap='RdYlGn_r')
plt.colorbar()
plt.show()
SofaSofa数据科学社区DS面试题库 DS面经
非常感谢
-
Mdws
2019-06-03 07:20
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
X = np.arange(-2, 2, 0.1)
Y = np.arange(-2, 2, 0.1)
X, Y = np.meshgrid(X, Y)
Z = X ** 2 + Y ** 2
ax.plot_surface(X, Y, Z, cmap=plt.cm.winter)
plt.show()