Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions openmc/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,8 @@ def plot(
legend: bool = False,
axis_units: str = 'cm',
outline: bool | str = False,
show_overlaps: bool = False,
overlap_color: Sequence[int] | str | None = None,
n_samples: int | None = None,
plane_tolerance: float = 1.,
legend_kwargs: dict | None = None,
Expand Down Expand Up @@ -933,6 +935,9 @@ def plot(
plot.pixels = pixels
plot.basis = basis
plot.color_by = color_by
plot.show_overlaps = show_overlaps
if overlap_color is not None:
plot.overlap_color = overlap_color
if colors is not None:
plot.colors = colors
self.plots.append(plot)
Expand Down
13 changes: 9 additions & 4 deletions openmc/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,21 @@
legend : bool
Whether a legend showing material or cell names should be drawn

.. versionadded:: 0.14.0
axis_units : {'km', 'm', 'cm', 'mm'}
Units used on the plot axis

.. versionadded:: 0.14.0
outline : bool or str
Whether outlines between color boundaries should be drawn. If set to
'only', only outlines will be drawn.

.. versionadded:: 0.14.0
axis_units : {'km', 'm', 'cm', 'mm'}
Units used on the plot axis

.. versionadded:: 0.14.0
show_overlaps: bool
Indicate whether or not overlapping regions are shown.
Default is False.
overlap_color: Iterable of int or str
Color to apply to overlapping regions. Default is red.
n_samples : int, optional
The number of source particles to sample and add to plot. Defaults
to None which doesn't plot any particles on the plot.
Expand Down
11 changes: 11 additions & 0 deletions tests/unit_tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,14 @@ def test_model_plot():
plot = model.plot(n_samples=1, plane_tolerance=0.1, basis="xy")
coords = plot.axes.collections[0].get_offsets().data.flatten()
assert (coords == np.array([])).all()

# modify model to include another cell that overlaps the original cell entirely
model.geometry.root_universe.add_cell(openmc.Cell(region=-surface))
axes = model.plot(show_overlaps=True)
white = np.array((1.0, 1.0, 1.0))
red = np.array((1.0, 0.0, 0.0))
axes_image = axes.get_images()[0]
image_data = axes_image.get_array()
# ensure that all of the data in the image data is either white or red
test_mask = (image_data == white) | (image_data == red)
assert np.all(test_mask), "Colors other than white or red found in overlap plot image"