【问题标题】:How to a reach solid surface in 3d surface in matplotlib?如何在 matplotlib 的 3d 表面中到达实体表面?
【发布时间】:2021-04-24 22:32:17
【问题描述】:

请问如何在 matplotlib 的 3d 曲面中到达实体曲面?我尝试多次应用 plot_surface,但细化有限且不够。透明度还是很明显的。更多样本也无济于事。

from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

# Coordinate for the cylinder
def data_for_cylinder_along_z(center_x,center_y,radius,height_z):
    z = np.linspace(0, height_z, 200)
    theta = np.linspace(0, 2*np.pi, 200)
    theta_grid, z_grid=np.meshgrid(theta, z)
    x_grid = radius*np.cos(theta_grid) + center_x
    y_grid = radius*np.sin(theta_grid) + center_y
    return x_grid,y_grid,z_grid

fig = plt.figure(figsize = (5,10))
ax = fig.add_subplot(111, projection='3d')

ax.set_xlim(-2, 2)
ax.set_ylim(-2, 2)
ax.set_zlim(0, 10)
 
ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([0.4, 0.4, 1.6, 1])) # (x, y, z) ration of sides

theta1 = np.linspace(0, 2*np.pi, 100)
r1 = np.linspace(-2, 0, 100)
t1, R1 = np.meshgrid(theta1, r1)

X1 = R1*np.cos(t1)
Y1 = R1*np.sin(t1)
Z1 = 3+R1*1.5+4

ax.set_xlabel('x axis')
ax.set_ylabel('y axis')
ax.set_zlabel('z axis')

ax.plot_surface(X1, Y1, Z1, color="dimgray")
ax.plot_surface(X1, Y1, Z1, color="dimgray")

# Cylinder
Xc,Yc,Zc = data_for_cylinder_along_z(0,0,2,4)

rep=10
for i in range(rep):
    ax.plot_surface(Xc, Yc, Zc, color = 'palegoldenrod')


plt.show()

【问题讨论】:

    标签: python-3.x matplotlib 3d surface


    【解决方案1】:

    您需要将antialiased 设置为True(通过反复试验找到,在文档中找不到描述):

    # Cylinder
    Xc,Yc,Zc = data_for_cylinder_along_z(0,0,2,4)
    ax.plot_surface(Xc, Yc, Zc, color='palegoldenrod', antialiased=False)
    

    【讨论】:

    • @Elena-Greg:这对您有用并回答了您的问题吗?
    猜你喜欢
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 2020-10-14
    • 2013-02-04
    • 2011-03-10
    • 1970-01-01
    • 2016-10-11
    • 2019-10-02
    相关资源
    最近更新 更多