Visualization#
pyRadPlan provides lightweight helpers for inspecting CT images, structure contours, and dose
distributions. They are deliberately thin wrappers around Matplotlib so that the returned
Axes objects can be further customized with standard Matplotlib calls.
plot_slice#
plot_slice() is the primary function. It renders a single
cross-sectional slice of the CT image, optionally overlaying a dose (or other quantity)
distribution and structure contours.
from pyRadPlan import plot_slice
plot_slice(
image_volume=ct,
cst=cst,
overlay=result["physical_dose"],
overlay_unit="Gy",
)
Key parameters#
Parameter |
Description |
|---|---|
|
CT image ( |
|
Structure set ( |
|
Dose or quantity array to display as a colour overlay. Can be a NumPy array or
|
|
Physical unit string (e.g. |
|
Slice orientation: |
|
Index of the slice to display. If |
|
Transparency of the dose overlay (0–1, default 0.5). |
|
Voxels below this fraction of the maximum overlay value are not shown (default 0.02). |
|
|
|
Matplotlib colormap name for the overlay (default |
|
|
|
Line width for structure contours (default 2.0). |
|
If given, the figure is saved to this path instead of displayed interactively. |
|
An existing |
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
for ax, plane in zip(axes, ["axial", "coronal", "sagittal"]):
plot_slice(
image_volume=ct,
cst=cst,
overlay=result["physical_dose"],
overlay_unit="Gy",
plane=plane,
show_plot=False,
ax=ax,
)
plt.tight_layout()
plt.show()
plot_multiple_slices#
plot_multiple_slices() creates a multi-panel figure showing
one or more overlays across one or more slices. The function accepts the same image_volume
and cst arguments as plot_slice(), but uses overlays and
view_slice for the displayed data:
Parameter |
Description |
|---|---|
|
One overlay image or a list of overlay images. |
|
One slice index or a list of slice indices. |
|
Orientation shared by all panels. |
from pyRadPlan.visualization import plot_multiple_slices
plot_multiple_slices(
image_volume=ct,
cst=cst,
overlays=result["physical_dose"],
overlay_unit="Gy",
view_slice=[40, 50, 60],
plane="axial",
)
Tips#
Pass
show_plot=Falseto suppress the interactive window (useful in scripts or notebooks that callplt.savefig()manually).overlaycan be any quantity array returned bydij.compute_result_ct_grid(), not just"physical_dose"— e.g.result["rbe_x_dose"]orresult["let_dose"].Structure colours are assigned automatically but can be customized by setting
voi.coloron individual VOI objects.