Fix #501: voxel_plot swapped x and z axes#734
Merged
Conversation
ax.set_xlim was using sz[2] and ax.set_zlim was using sz[0], which flipped the x and z axes vs. the input array's first and last dimensions. With this fix, set_xlim/ylim/zlim follow sz[0]/sz[1]/sz[2] so the rendered axes match the input shape and MATLAB k-Wave's voxelPlot behaviour. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #734 +/- ##
==========================================
+ Coverage 74.82% 74.84% +0.02%
==========================================
Files 56 57 +1
Lines 8095 8114 +19
Branches 1577 1579 +2
==========================================
+ Hits 6057 6073 +16
- Misses 1422 1423 +1
- Partials 616 618 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Address two related P2 findings from Greptile on PR #734: - The previous `matplotlib.use("Agg", force=True)` call lived inside the test body, but kwave.utils.plot imports matplotlib.pyplot at module load, so the backend was already chosen by the time the module-level `from kwave.utils.plot import voxel_plot` ran. On headless CI without DISPLAY, that import could fail before the test ever executed. - With the backend set at module level, the in-test use(...) call and `import matplotlib` were redundant. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
voxel_plotinkwave/utils/plot.pywas usingsz[2]for the x-axis limit andsz[0]for the z-axis limit, which mirrored the rendered output relative to the input array's first and last dimensions (and relative to MATLAB k-Wave'svoxelPlot).set_xlim/ylim/zlimusesz[0]/sz[1]/sz[2](the fix the issue reporter suggested).tests/test_utils.pythat callsvoxel_ploton a(4, 8, 12)array (asymmetric so a swap is visible) and asserts each axis limit follows the corresponding shape dim.Test plan
test_voxel_plot_axis_limits_match_input_shapepasses locallyruff check+ruff format --checkcleanCloses #501
🤖 Generated with Claude Code
Greptile Summary
Fixes the swapped x/z axis limits in
voxel_plot— the old code mappedsz[2]to xlim andsz[0]to zlim, mirroring the output relative to the input array's first and last dimensions. The fix swaps them back so each axis limit follows the corresponding shape dimension, matching MATLAB k-Wave'svoxelPlotbehavior.kwave/utils/plot.py: Two-line swap restoringset_xlim→sz[0]andset_zlim→sz[2].tests/test_utils.py:matplotlib.use("Agg")moved to module level (beforekwave.utils.plotis imported, which itself importsmatplotlib.pyplot), and a new regression test asserts each axis limit against the expected shape dimension using an asymmetric(4, 8, 12)array.Confidence Score: 5/5
Safe to merge — the change is a minimal two-line swap that corrects a long-standing axis-mapping bug, backed by a targeted regression test.
The fix is isolated to two lines in voxel_plot, the logic is straightforward and directly matches the MATLAB reference implementation, and the new test uses an asymmetric array that would fail on the old code, confirming the correction.
No files require special attention.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["voxel_plot(mat)"] --> B["mat.shape → sz"] B --> C{axis_tight?} C -- "False (default)" --> D["set_xlim([0.5, sz[0]+0.5])"] D --> E["set_ylim([0.5, sz[1]+0.5])"] E --> F["set_zlim([0.5, sz[2]+0.5])"] C -- "True" --> G["skip axis limit setup"]Reviews (2): Last reviewed commit: "Set matplotlib Agg backend at module lev..." | Re-trigger Greptile