Skip to content

Fix per-line plot styles being ignored when plotting parameters - #287

Merged
henrikjacobsenfys merged 3 commits into
developfrom
fix/plot-styles-lost-with-coords
Nov 12, 2026
Merged

henrikjacobsenfys merged 3 commits into
developfrom
fix/plot-styles-lost-with-coords

Conversation

@henrikjacobsenfys

Copy link
Copy Markdown
Member

Problem

Since #271, ParameterAnalysis.plot() draws the model as points instead of a dashed line (visible in tutorial 1). Colours no longer pair data with model, and the legend labels are gone. Analysis.plot_parameters() is affected the same way: it loses its hollow markers and labels.

Cause

#271 started passing coords=[x_axis] to plopp.plot. plopp implements coords= by calling DataArray.rename_dims. In scipp 26.9, rename_dims drops the DataArray's name. plopp looks up per-line style dicts (linestyle={name: ...}, marker, color, ...) by that name, so every style was silently ignored and plopp fell back to its default markers. Both x_axis='Q' and x_axis='Q^2' were affected.

Fix

  • Replace add_x_axis_coord with with_x_axis_dim. It makes the x-axis coordinate the dimension before plotting, so we no longer pass coords= to plopp.
    • It renames whichever dimension the Q coordinate lies along, as plopp did, so data whose dimension isn't called Q still works.
  • Note in the **kwargs docstrings that passing coords= yourself makes plopp ignore the styles.
  • tests/conftest.py pins matplotlib's Agg backend. Without it, tests that render for real open Tk windows on Windows and fail intermittently with Tcl errors.

Tests

  • New tests render with plopp for real (no mocking) and check the lines' linestyle, marker and labels, for both Q and Q^2. They fail on develop and pass with this change.
  • New test for a Q coordinate on a dimension not named Q.
  • Existing tests updated for the removed coords= kwarg.
  • pixi run check passes, and so do the Bayesian sampling integration tests.

An agent reviewed the change, and its findings are addressed in the second commit.

🤖 Generated with Claude Code

henrikjacobsenfys and others added 2 commits November 9, 2026 13:21
Since #271, ParameterAnalysis.plot and Analysis.plot_parameters passed
coords=[x_axis] to plopp.plot. plopp implements coords= with
DataArray.rename_dims, which drops the DataArray's name, and plopp looks
up per-line style dicts (linestyle, marker, color, ...) by that name. All
styles were therefore silently ignored: the ParameterAnalysis model was
drawn as points instead of a dashed line, and legend labels were lost.

Replace add_x_axis_coord with with_x_axis_dim, which makes the x-axis
coordinate the dimension before plotting, so coords= is no longer needed.
Add tests that render with plopp for real and check the line styles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- with_x_axis_dim renames the dimension the Q coordinate lies along
  instead of assuming it is named 'Q', as plopp's coords= did.
- tests/conftest.py pins the Agg backend, so tests that render for real
  don't open Tk windows and fail intermittently on Windows.
- Document that passing plopp's coords= makes per-line styles be ignored.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.18%. Comparing base (762b081) to head (5527f9a).
⚠️ Report is 18 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #287      +/-   ##
===========================================
+ Coverage    98.15%   98.18%   +0.03%     
===========================================
  Files           60       64       +4     
  Lines         6066     6243     +177     
  Branches      1022     1042      +20     
===========================================
+ Hits          5954     6130     +176     
- Misses          58       59       +1     
  Partials        54       54              
Flag Coverage Δ
unittests 98.18% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/easydynamics/analysis/analysis.py 97.68% <100.00%> (+<0.01%) ⬆️
src/easydynamics/analysis/parameter_analysis.py 98.91% <100.00%> (-0.36%) ⬇️
src/easydynamics/utils/plotting.py 95.45% <100.00%> (+7.57%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@henrikjacobsenfys henrikjacobsenfys added [scope] bug Bug report or fix (major.minor.PATCH) [priority] medium Normal/default priority labels Nov 9, 2026
@henrikjacobsenfys
henrikjacobsenfys merged commit 989a2c6 into develop Nov 12, 2026
33 checks passed
henrikjacobsenfys added a commit that referenced this pull request Nov 12, 2026
The conflict resolution kept a call to add_x_axis_coord, which #287
replaced with with_x_axis_dim, and applied with_x_axis_dim to the dict
of DataArrays instead of to the data and model Datasets. The Q^2 test
took #287's assertions, which treat the plotted object as one Dataset.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
henrikjacobsenfys added a commit that referenced this pull request Nov 12, 2026
* Allow evaluating the ParameterAnalysis model on a custom Q grid

calculate_model_dataset and plot take an optional Q (sc.Variable) so the
model can be drawn on a finer grid than the data. Closes #200.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Validate the Q grid in ParameterAnalysis.plot and calculate_model_dataset

Q must be a 1D sc.Variable with a unit of inverse length. plot checks it
up front, so a bad Q is no longer silently ignored when there are no
bindings to evaluate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Validate Q with the shared _validate_and_convert_Q

Replaces the ParameterAnalysis-specific check, so the Q grid follows the
same rules as everywhere else: a single dimension named 'Q', a unit
convertible to 1/angstrom, and positive values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Keep the model dims as 'Q' and correct the plot comment

Q is validated to have the single dimension 'Q', so the model array can
keep dims=['Q'] as before. The comment said data and model are plotted
as separate Datasets; they are passed as one dict of DataArrays.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

* Fix the merge of develop into the finer-Q-grid branch

The conflict resolution kept a call to add_x_axis_coord, which #287
replaced with with_x_axis_dim, and applied with_x_axis_dim to the dict
of DataArrays instead of to the data and model Datasets. The Q^2 test
took #287's assertions, which treat the plotted object as one Dataset.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[priority] medium Normal/default priority [scope] bug Bug report or fix (major.minor.PATCH)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant