3D Contour plot from data using Mayavi / Python

后端 未结 2 459
情歌与酒
情歌与酒 2021-01-31 06:26

I would like to do a 3D contour plot using Mayavi in exactly the same way as the third figure on this page (a hydrogen electron cloud model) :

http://www.sethanil.com/py

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 07:03

    You can use delaunay3d filter to create cells from points. Then you can create an iso_surface() for the output UnstructuredGrid of delaunay3d. If you want ImageData, you can use image_data_probe filter.

    import numpy as np
    from tvtk.api import tvtk
    from mayavi import mlab
    
    points = np.random.normal(0, 1, (1000, 3))
    ug = tvtk.UnstructuredGrid(points=points)
    ug.point_data.scalars = np.sqrt(np.sum(points**2, axis=1))
    ug.point_data.scalars.name = "value"
    ds = mlab.pipeline.add_dataset(ug)
    delaunay = mlab.pipeline.delaunay3d(ds)
    iso = mlab.pipeline.iso_surface(delaunay)
    iso.actor.property.opacity = 0.1
    iso.contour.number_of_contours = 10
    mlab.show()
    

    enter image description here

提交回复
热议问题