Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose universe plotting for the cell class #2648

Merged
merged 2 commits into from
Aug 20, 2023
Merged
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
61 changes: 61 additions & 0 deletions openmc/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,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