Skip to content

Commit

Permalink
Expose universe plotting for the cell class (#2648)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
pshriwise and paulromano authored Aug 20, 2023
1 parent 03f98e8 commit 8e77a1f
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions openmc/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,67 @@ def clone(self, clone_materials=True, clone_regions=True, memo=None):

return memo[self]

def plot(self, *args, **kwargs):
"""Display a slice plot of the cell.
.. 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 openmc.Universe(cells=[self]).plot(*args, **kwargs)

def create_xml_subelement(self, xml_element, memo=None):
"""Add the cell's xml representation to an incoming xml element
Expand Down

0 comments on commit 8e77a1f

Please sign in to comment.