我试图谷歌如何做到这一点,但似乎无法让它工作。非常感谢任何帮助或建议。这是我从谷歌搜索尝试但是假设我只是做得不对
import numpy as np
import matplotlib.pyplot as plt
def prob_10(x,y):
return x*np.exp(-x**2/2-y**3/3+y)
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
x = y = np.arange(-3.0, 3.0, 0.05)
X, Y = np.meshgrid(x, y)
z = prob_10(x,y)
不断收到此错误 matplotlib.figure.Figure at 0x7fa34fd9c310
答案 0 :(得分:0)
试试这个:
(您可能会发现plot_surface更有用,您可能希望为您的轴设置限制。有关更多示例,请查看此处:http://matplotlib.org/gallery.html#mplot3d)
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
c='r'
m='o'
x = np.arange(-3.0, 3.0, 0.05)
y = np.arange(-3.0, 3.0, 0.05)
X,Y = np.meshgrid(x, y)
Z = X*np.exp(-X**2/2-Y**3/3+Y)
ax.scatter(X, Y, Z, c=c, marker=m)
#ax.plot_surface(X, Y, Z)
plt.show()
分散图:
Plot_Surface: