注釈
Go to the end to download the full example code.
スケーリングされたガウスポイント#
この例では, 'points_gaussian'
スタイルを使用して球体をプロットし,動的な半径でスケーリングする方法を示します.
from __future__ import annotations
import numpy as np
import pyvista as pv
まず、トーラスの端に球の位置と半径をランダムに生成します.
# Seed the rng for reproducibility
rng = np.random.default_rng(seed=0)
N_SPHERES = 10_000
theta = rng.uniform(0, 2 * np.pi, N_SPHERES)
phi = rng.uniform(0, 2 * np.pi, N_SPHERES)
torus_radius = 1
tube_radius = 0.3
radius = torus_radius + tube_radius * np.cos(phi)
rad = rng.random(N_SPHERES) * 0.01
pos = np.zeros((N_SPHERES, 3))
pos[:, 0] = radius * np.cos(theta)
pos[:, 1] = radius * np.sin(theta)
pos[:, 2] = tube_radius * np.sin(phi)
次に,PolyDataオブジェクトを作成し,球の位置と半径をデータ配列として追加します.
最後に, points_gaussian
スタイルを使用して球体をプロットし,半径でスケーリングします.
pl = pv.Plotter()
actor = pl.add_mesh(
pdata,
style='points_gaussian',
emissive=False,
render_points_as_spheres=True,
show_scalar_bar=False,
)
actor.mapper.scale_array = 'radius'
pl.camera.zoom(1.5)
pl.show()

同じプロットを emissive=True
で表示します.
pl = pv.Plotter()
pl.background_color = 'k'
actor = pl.add_mesh(
pdata,
style='points_gaussian',
emissive=True,
render_points_as_spheres=True,
show_scalar_bar=False,
)
actor.mapper.scale_array = 'radius'
pl.camera.zoom(1.5)
pl.show()

Total running time of the script: (0 minutes 0.602 seconds)