Skip to content

Fixed plotting issue by scaling source locations with axis units - #3668

Merged
paulromano merged 1 commit into
openmc-dev:developfrom
shimwell:fixing-source-plot-scaling-issue
Dec 5, 2025
Merged

paulromano merged 1 commit into
openmc-dev:developfrom
shimwell:fixing-source-plot-scaling-issue

Conversation

@shimwell

@shimwell shimwell commented Dec 5, 2025 •

Copy link
Copy Markdown
Member

This PR simply scales the location of the source scatter points so that they are in the same units as the axis

Fixes #3660

Checklist

  • I have performed a self-review of my own code
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)

I have made this script to demonstrate the issue and test the solution

import openmc
import matplotlib.pyplot as plt
openmc.config['cross_sections'] = '/home/jon/nuclear_data/cross_sections.xml'
major_radius = 5.0
minor_radius = 1.0
torus = openmc.ZTorus(a=major_radius, b=minor_radius, c=minor_radius)
outer_sphere = openmc.Sphere(r=10.0, boundary_type='vacuum')
torus_cell = openmc.Cell(name='torus')
torus_cell.region = -torus & -outer_sphere
void_cell = openmc.Cell(name='void')
void_cell.region = +torus & -outer_sphere
universe = openmc.Universe(cells=[torus_cell, void_cell])
geometry = openmc.Geometry(universe)
source = openmc.IndependentSource()
source.space = openmc.stats.CylindricalIndependent(
    r=openmc.stats.Discrete([major_radius], [1.0]),  # Ring at major radius
    phi=openmc.stats.Uniform(0, 2*3.14),  # Full circle
    z=openmc.stats.Discrete([0.0], [1.0]),  # At z=0
    origin=(0.0, 0.0, 0.0)
)
settings = openmc.Settings()
settings.source = source
settings.batches = 10
settings.particles = 1000
settings.run_mode = 'fixed source'
settings.export_to_xml()
model = openmc.model.Model(geometry=geometry, settings=settings)
model.plot(
    origin=[0, 0, 0],
    width=[15, 15],
    pixels=[1000, 1000],
    basis='xy',
    color_by='cell',
    n_samples=100
)
model.plot(
    origin=[0, 0, 0],
    width=[15, 15],
    pixels=[1000, 1000],
    basis='xy',
    color_by='cell',
    axis_units='m',  # <--- note this is in meters
    n_samples=100
)
plt.show()

@paulromano paulromano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@paulromano
paulromano merged commit f281392 into openmc-dev:develop Dec 5, 2025
15 checks passed
apingegno pushed a commit to apingegno/openmc that referenced this pull request May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

slice plot not scaling source locations when axis_units used

2 participants