可视化Vispy圆柱中的HSV颜色

时间:2020-06-19 17:27:02

标签: python matplotlib mayavi mayavi.mlab vispy

我想在Vispy的3D散点图中可视化HSV色彩空间,例如Wikipedia图像:https://es.wikipedia.org/wiki/Archivo:HSV_color_solid_cylinder_saturation_gray.png

我正在为圆柱坐标生成随机点,然后转换为XYZ以绘制圆柱,并将原始点(0-1范围内)作为颜色传递给Vispy。

我的颜色太少了。我该怎么做才能获得类似Wikipedia的外观图像?

My HSV cylinder

    from vispy.color import ColorArray
    import numpy as np
    import vispy.scene


    def scale(arr):
        """ Scale to 0-1 range """
        return (arr - np.min(arr)) / (np.max(arr) - np.min(arr))

    N = 120000
    radius = np.random.rand(N, 1)
    theta = np.deg2rad(360 * np.random.rand(N, 1))
    altitude = np.random.rand(N, 1)

    # From Cylindrical to Cartesian coordinates 
    x = radius * np.cos(theta)
    y = radius * np.sin(theta)
    z = altitude

    color1 = scale(theta) 
    color2 = radius
    color3 = altitude

    Scatter3D = vispy.scene.visuals.create_visual_node(vispy.visuals.MarkersVisual)

    canvas = vispy.scene.SceneCanvas(keys='interactive', show=True)
    view = canvas.central_widget.add_view()
    view.camera = 'turntable'
    view.camera.distance = 5

    pos = np.concatenate([x,y,z], axis=1)
    colors = ColorArray(color=np.concatenate([color1, color2, color3], axis=1), color_space='hsv')
    sizes = 5 * np.ones((N,1))

    p1 = Scatter3D(parent=view.scene)
    p1.set_gl_state('translucent', blend=True, depth_test=True)
    p1.set_data(pos,
                face_color=colors,
                symbol='o',
                size=sizes[:,0],
                edge_width=0.5, 
                edge_color=None
    )

    axis = vispy.scene.visuals.XYZAxis(parent=view.scene)
    vispy.app.run()

0 个答案:

没有答案