繁体   English   中英

有没有办法在 python 的圆柱图上绘制 3d 点?

[英]Is there a way to graph 3d points on a cylinder graph in python?

我正在根据作为 xyz 轴的色相、亮度和饱和度绘制不同的颜色值。 它与 matplotlib 配合使用效果很好,这是一张照片。

在此处输入图像描述

但是最近我在 inte.net 上看到了一个基于圆柱体的图形图像

圆柱图

我在 inte.net 上找不到任何关于它的信息,而且 matplotlib 似乎不支持制作这种图表。 有谁知道 python 中圆柱图上 plot 散点的方法?

为了在圆柱体的表面上放置点,您必须对表面进行参数化。 这是一种方式:

import numpy as np
import matplotlib.pyplot as plt

def cylinder(R, z_min, z_max, theta_max, N):
    z = np.random.uniform(z_min, z_max, N)
    theta = np.random.uniform(0, theta_max, N)
    x = R * np.cos(theta)
    y = R * np.sin(theta)
    return x, y, z

def dics(z, R_max, theta_max, N):
    r = np.random.uniform(0, R_max, N)
    theta = np.random.uniform(0, theta_max, N)
    x = r * np.cos(theta)
    y = r * np.sin(theta)
    return x, y, z * np.ones_like(x)

def plane(theta, R_max, z_min, z_max, N):
    r = np.random.uniform(0, R_max, N)
    x = r * np.cos(theta)
    y = r * np.sin(theta)
    z = np.random.uniform(z_min, z_max, N)
    return x, y, z

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection="3d")

N = 1000
z_min = -1
z_max = 1
R = 3
theta_max = 1.5 * np.pi

# points on the cylindrical surface
x_cyl, y_cyl, z_cyl = cylinder(R, z_min, z_max, theta_max, N)
ax.scatter(x_cyl, y_cyl, z_cyl)

# points on the top cap
x_top, y_top, z_top = dics(z_max, R, theta_max, N)
ax.scatter(x_top, y_top, z_top)

# points on the bottom cap
x_bottom, y_bottom, z_bottom = dics(z_min, R, theta_max, N)
ax.scatter(x_bottom, y_bottom, z_bottom)

# points on the first slice-wall
x1, y1, z1 = plane(0, R, z_min, z_max, N)
ax.scatter(x1, y1, z1)

# points on the second slice-wall
x2, y2, z2 = plane(theta_max, R, z_min, z_max, N)
ax.scatter(x2, y2, z2)

plt.show()

在此处输入图像描述

然后,您必须修改上述函数以返回角度theta和半径r ,这样您就可以根据 H、S、V 应用 colors,但这留给您作为练习:)

编辑:如果你只是想将 plot 散点到切片圆柱体的体积中,你可以这样修改cylinder function:

def cylinder(R, z_min, z_max, theta_max, N):
    z = np.random.uniform(z_min, z_max, N)
    theta = np.random.uniform(0, theta_max, N)
    r = np.random.uniform(0, R, N)
    x = r * np.cos(theta)
    y = r * np.sin(theta)
    return x, y, z

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM