Display geometric models in "three views" mode
Description
we can display geometric models in three views. like below:
just add a Geometry.plot() method like Geometry.plot( basis='xyz' ) or Geometry.plot( basis='3views' )?
a simple code as below:
import matplotlib.pyplot as plt
fig, axes = plt.subplots(2, 2, sharex='all', sharey='all', figsize=(12, 12))
ax1, ax2, ax3, ax4 = axes[0][0], axes[0][1], axes[1][0], axes[1][1]
my_geometry.plot(basis='xz', color_by='cell', colors=color_assignment, axes=ax1)
ax1.set_xlabel('x')
ax1.set_ylabel('z')
my_geometry.plot(basis='yz', color_by='cell', colors=color_assignment, axes=ax2)
ax2.set_xlabel('y')
ax2.set_ylabel('z')
my_geometry.plot(basis='xy', color_by='cell', colors=color_assignment, axes=ax3)
ax3.set_xlabel('x')
ax3.set_ylabel('y')
ax4.set_visible(False)
plt.show()
plt.savefig('xyz.png')
Alternatives
Compatibility
In engineering drawings this is commonly called an orthographic projection. One of the most important things in this set of views is that features always line up in their perpendicular views.
I like this idea but I think some more thought on the basis name is needed because it might be nice sometimes to change which is the base projection.
How about setting the 2D basis by each combination in the 3D basis? Example:
basis='xyz' -> xy, xz, yz
basis='zxy' -> zx, zy, xy
A way to display geometric models in orthographic projection ( 3d mode ) with pyvista.
Inspired by: https://github.com/fusion-energy/neutronics-workshop/issues/291
I try the task09 - 1.
# %%
# pip install "pyvista[jupyter]"
vox_plot = openmc.Plot(name=fig_name)
vox_plot.type = "voxel"
vox_plot.width = my_geometry.bounding_box.width
vox_plot.origin = my_geometry.bounding_box.center
vox_plot.pixels = [100, 100, 100]
vox_plot.color_by = "material" # or "cell"
# export to a *.vti file
vtk_file = vox_plot.to_vtk(fig_name)
# %%
import pyvista as pv
pv.set_jupyter_backend("client")
mesh = pv.read(vtk_file)
mesh
# %%
id = mesh.cell_data.get_array("id")
print(set(id)) # material id: 1; vacuum id: -1, -2
# %%
pl = pv.Plotter()
slice_x = mesh.slice(normal=(1, 0, 0), origin=(0, 0, 0))
slice_y = mesh.slice(normal=(0, 1, 0), origin=(0, 0, 0))
slice_z = mesh.slice(normal=(0, 0, 1), origin=(0, 0, 0))
pl.add_mesh(slice_x, scalars="id", opacity=0.8)
pl.add_mesh(slice_y, scalars="id", opacity=0.8)
pl.add_mesh(slice_z, scalars="id", opacity=0.8)
pl.enable_parallel_projection()
pl.show_grid()
pl.show()