From 9897fe372797d72fd14d285bad3f8ef2c91b451c Mon Sep 17 00:00:00 2001 From: James Logan Date: Wed, 17 Aug 2022 13:45:50 -0400 Subject: [PATCH 1/4] add pass-through to allow plotting geometry on existing axes --- openmc/universe.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 4aa1775fb1..c95a80f062 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -360,12 +360,15 @@ class Universe(UniverseBase): # Create a figure sized such that the size of the axes within # exactly matches the number of pixels specified - px = 1/plt.rcParams['figure.dpi'] - fig, ax = plt.subplots() - params = fig.subplotpars - width = pixels[0]*px/(params.right - params.left) - height = pixels[0]*px/(params.top - params.bottom) - fig.set_size_inches(width, height) + if kwargs.get("ax") is None: + px = 1/plt.rcParams['figure.dpi'] + fig, ax = plt.subplots() + params = fig.subplotpars + width = pixels[0]*px/(params.right - params.left) + height = pixels[0]*px/(params.top - params.bottom) + fig.set_size_inches(width, height) + else: + ax = kwargs.pop("ax") # Plot image and return the axes return ax.imshow(img, extent=(x_min, x_max, y_min, y_max), **kwargs) From 00f05719069cfdfe4848487eb4583baca629d705 Mon Sep 17 00:00:00 2001 From: James Logan Date: Wed, 24 Aug 2022 09:43:13 -0400 Subject: [PATCH 2/4] add Axes as an argument to Universe.plot instead of popping it from kwargs --- openmc/universe.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index c95a80f062..768c2ba297 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -272,7 +272,7 @@ class Universe(UniverseBase): def plot(self, origin=(0., 0., 0.), width=(1., 1.), pixels=(200, 200), basis='xy', color_by='cell', colors=None, seed=None, - openmc_exec='openmc', **kwargs): + openmc_exec='openmc', axes=None, **kwargs): """Display a slice plot of the universe. Parameters @@ -302,6 +302,7 @@ class Universe(UniverseBase): Seed for the random number generator openmc_exec : str Path to OpenMC executable. + axes : matplotlib.Axes to draw to .. versionadded:: 0.13.1 **kwargs @@ -360,18 +361,18 @@ class Universe(UniverseBase): # Create a figure sized such that the size of the axes within # exactly matches the number of pixels specified - if kwargs.get("ax") is None: + if axes is None: px = 1/plt.rcParams['figure.dpi'] - fig, ax = plt.subplots() + fig, axes = plt.subplots() params = fig.subplotpars width = pixels[0]*px/(params.right - params.left) height = pixels[0]*px/(params.top - params.bottom) fig.set_size_inches(width, height) else: - ax = kwargs.pop("ax") + pass # Plot image and return the axes - return ax.imshow(img, extent=(x_min, x_max, y_min, y_max), **kwargs) + return axes.imshow(img, extent=(x_min, x_max, y_min, y_max), **kwargs) def add_cell(self, cell): """Add a cell to the universe. From bd2bab3f568b7cb70e9556974218dd11d80e93d4 Mon Sep 17 00:00:00 2001 From: James Logan Date: Thu, 25 Aug 2022 11:57:36 -0400 Subject: [PATCH 3/4] remove explicit else-pass --- openmc/universe.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 768c2ba297..2994540aed 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -368,8 +368,6 @@ class Universe(UniverseBase): width = pixels[0]*px/(params.right - params.left) height = pixels[0]*px/(params.top - params.bottom) fig.set_size_inches(width, height) - else: - pass # Plot image and return the axes return axes.imshow(img, extent=(x_min, x_max, y_min, y_max), **kwargs) From 9e80a73369b31c32c8a81791b2853ca2476ba883 Mon Sep 17 00:00:00 2001 From: James Logan Date: Tue, 30 Aug 2022 10:20:35 -0400 Subject: [PATCH 4/4] Update openmc/universe.py Co-authored-by: Paul Romano --- openmc/universe.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openmc/universe.py b/openmc/universe.py index 2994540aed..cdb72bf6ef 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -302,7 +302,8 @@ class Universe(UniverseBase): Seed for the random number generator openmc_exec : str Path to OpenMC executable. - axes : matplotlib.Axes to draw to + axes : matplotlib.Axes + Axes to draw to .. versionadded:: 0.13.1 **kwargs