Skip to content

Commit

Permalink
Expose universe plotting for the geometry class (#2661)
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell authored Aug 22, 2023
1 parent d687ce4 commit ffbf1b9
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions openmc/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,3 +734,61 @@ def clone(self) -> Geometry:
clone = deepcopy(self)
clone.root_universe = self.root_universe.clone()
return clone

def plot(self, *args, **kwargs):
"""Display a slice plot of the geometry.
.. versionadded:: 0.13.4
Parameters
----------
origin : iterable of float
Coordinates at the origin of the plot. If left as None then the
bounding box center will be used to attempt to ascertain the origin.
Defaults to (0, 0, 0) if the bounding box is not finite
width : iterable of float
Width of the plot in each basis direction. If left as none then the
bounding box width will be used to attempt to ascertain the plot
width. Defaults to (10, 10) if the bounding box is not finite
pixels : Iterable of int or int
If iterable of ints provided, then this directly sets the number of
pixels to use in each basis direction. If int provided, then this
sets the total number of pixels in the plot and the number of pixels
in each basis direction is calculated from this total and the image
aspect ratio.
basis : {'xy', 'xz', 'yz'}
The basis directions for the plot
color_by : {'cell', 'material'}
Indicate whether the plot should be colored by cell or by material
colors : dict
Assigns colors to specific materials or cells. Keys are instances of
:class:`Cell` or :class:`Material` and values are RGB 3-tuples, RGBA
4-tuples, or strings indicating SVG color names. Red, green, blue,
and alpha should all be floats in the range [0.0, 1.0], for example:
.. code-block:: python
# Make water blue
water = openmc.Cell(fill=h2o)
universe.plot(..., colors={water: (0., 0., 1.))
seed : int
Seed for the random number generator
openmc_exec : str
Path to OpenMC executable.
axes : matplotlib.Axes
Axes to draw to
legend : bool
Whether a legend showing material or cell names should be drawn
legend_kwargs : dict
Keyword arguments passed to :func:`matplotlib.pyplot.legend`.
outline : bool
Whether outlines between color boundaries should be drawn
axis_units : {'km', 'm', 'cm', 'mm'}
Units used on the plot axis
**kwargs
Keyword arguments passed to :func:`matplotlib.pyplot.imshow`
Returns
-------
matplotlib.axes.Axes
Axes containing resulting image
"""

return self.root_universe.plot(*args, **kwargs)

0 comments on commit ffbf1b9

Please sign in to comment.