Skip to content

Fix source plotting scale bug - #4189

Merged
paulromano merged 1 commit into
openmc-dev:developfrom
shimwell:fix/model-plot-source-axis-limits
Oct 13, 2026
Merged

paulromano merged 1 commit into
openmc-dev:developfrom
shimwell:fix/model-plot-source-axis-limits

Conversation

@shimwell

@shimwell shimwell commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Description

The source points can outside the requested plot width and currently expand the axis limits.

Fixing this by setting the limits after drawing the scatter

AI Assistance

Code changes done by a human but I got GPT-6.1 Sol to review it.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 18) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

Summary by CodeRabbit

  • Bug Fixes
    • Plot views now retain the requested x/y limits, preventing sampled source points outside the view from expanding the axes.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9f53c0ae-61a3-4f32-ac04-333b83a430b9
📥 Commits

Reviewing files that changed from the base of the PR and between aa4afc4 and 5983e8d.

📒 Files selected for processing (1)
  • openmc/model/model.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Model.plot now applies the requested x and y limits after plotting and source-point sampling in all outline modes. The outline-only path continues to set an equal aspect ratio.

Changes: Model plot axis limits

Layer / File(s) Summary
Apply requested axis limits
openmc/model/model.py
The outline-only branch retains equal aspect ratio. After plotting and source-point sampling, plot sets the requested x and y limits regardless of outline mode.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: paulromano

Merge Risk: ⚪ Minimal · up to 5983e

The requested bounds are applied after plotting and source sampling, addressing the reported axis expansion. No concrete merge-blocking regression is established.

Pre-merge checks · Passed 5
Passed Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description explains the source plotting bug and the fix. It discloses AI assistance and records the relevant checklist items. It does not identify an issue number, specify the AI harness or reaso…
Title check Passed The title clearly and concisely identifies the main change: fixing the source plotting scale bug.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@shimwell

Copy link
Copy Markdown
Member Author

I have also been testing locally with this script

import matplotlib.pyplot as plt
import openmc

sphere = openmc.Sphere(r=10.0, boundary_type="vacuum")
model = openmc.Model(geometry=openmc.Geometry([
    openmc.Cell(region=-sphere)
]))
model.settings.source = openmc.IndependentSource(
    space=openmc.stats.Point((8.0, 0.0, 0.0))
)

fig, axes = plt.subplots(1, 2, figsize=(10, 4))
for ax, n_samples, title in zip(
    axes, [None, 1], ["Without source overlay", "With source overlay"]
):
    model.plot(
        origin=(0, 0, 0), width=(4, 4), pixels=(100, 100),
        n_samples=n_samples, axes=ax,
        source_kwargs={"color": "red", "s": 100},
    )
    ax.set_title(title)
    ax.set_xlabel("x [cm]")
    ax.set_ylabel("y [cm]")
    print(title, "x limits:", ax.get_xlim(), "y limits:", ax.get_ylim())

fig.tight_layout()
plt.show()

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Autofix could not be updated. Open Coding to check access and billing.

@paulromano paulromano changed the title fixing source plotting scale bug Fix source plotting scale bug Oct 13, 2026

@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 @shimwell!

@paulromano
paulromano merged commit 509430d into openmc-dev:develop Oct 13, 2026
25 of 30 checks passed
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.

2 participants