我正在尝试使用 Matplotlib 同时绘制一个平面和 3D 中的一些点。
我没有错误,只是点不会出现。
我可以在不同时间绘制一些点和平面,但不能同时绘制。
代码部分如下所示:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
point = np.array([1, 2, 3])
normal = np.array([1, 1, 2])
point2 = np.array([10, 50, 50])
# a plane is a*x+b*y+c*z+d=0
# [a,b,c] is the normal. Thus, we have to calculate
# d and we're set
d = -point.dot(normal)
# create x,y
xx, yy = np.meshgrid(range(10), range(10))
# calculate corresponding z
z = (-normal[0] * xx - normal[1] * yy - d) * 1. /normal[2]
# plot the surface
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(xx, yy, z, alpha=0.2)
#and i would like to plot this point :
ax.scatter(point2[0] , point2[1] , point2[2], color='green')
plt.show()
只是为了添加@suever的答案,你没有理由不能创建Axes
然后绘制曲面和其上的散点。那么就没有必要使用ax.hold()
:
# Create the figure
fig = plt.figure()
# Add an axes
ax = fig.add_subplot(111,projection='3d')
# plot the surface
ax.plot_surface(xx, yy, z, alpha=0.2)
# and plot the point
ax.scatter(point2[0] , point2[1] , point2[2], color='green')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)