首页 > 解决方案 > 使用 Axes3D.plot_wireframe 和 Axes3D.scatter 绘图:线框隐藏的散点

问题描述

我使用 绘制圆盘的离散表面,并在同一张图上使用(附图)Axes3d.plot_wireframe叠加对应于圆盘中心的点。Axes3d.scatter我的问题是只有在配置文件中看到光盘时才能看到该点。无论视图如何,我都希望它可见。我也加入了我的脚本的一部分(抱歉,如果它没有按应有的方式出现)。

我尝试更改脚本中绘图的顺序,尝试'zorder'在两个绘图中添加一个参数,并且我还尝试更改散点图中的标记大小,但它不起作用。

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import pylab as plt
import numpy as np

# data to build the disc
r = np.linspace(0, 5e-3, 30)
psi = np.linspace(0, 2*np.pi, 30)
n = np.array([0.70710678, 0, 0.70710678])
e2 = np.array([0.70710678, 0, -0.70710678])
e3 = np.array([0, 1, 0])
Oc = np.array([0, 0, 0])
R, PSI = np.meshgrid(r, psi)
OpP = np.zeros((len(r),len(psi),3), dtype=float)
OpP[:,:,0] = np.zeros((len(r),len(psi)), dtype=float)
OpP[:,:,1] = R*np.cos(PSI)  
OpP[:,:,2] = R*np.sin(PSI)  
Mrot = np.zeros((3,3), dtype=float)
Mrot[0,:] = n
Mrot[1,:] = e2
Mrot[2,:] = e3
Ocx = Oc[0]; Ocy = Oc[1]; Ocz = Oc[2]
xp = Ocx + np.dot(OpP, Mrot)[:,:,0]
yp = Ocy + np.dot(OpP, Mrot)[:,:,1]
zp = Ocz + np.dot(OpP, Mrot)[:,:,2]

# Plotting
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_wireframe(zp,yp,xp, label='piston')
ax.scatter(Ocz, Ocy, Ocx, zdir='z', s=40, color='red', label='Oc')
plt.gca().invert_yaxis()
plt.legend()
plt.show()

光盘的剖面图: 在此处输入图像描述

定向盘: 在此处输入图像描述

标签: pythonmatplotlib

解决方案


可以设置绘图参数的一些值以获得更好的绘图。尝试用这些替换相关的代码行:

ax.plot_wireframe(zp,yp,xp, label='piston', \
            linewidth=0.5, \
            alpha=0.7)
ax.scatter(Ocz, Ocy, Ocx, zdir='z', \
            s=80, \
            color='red', label='Oc')

3d 图像


推荐阅读