Skip to content

2D plots: draw into given axes, optional show, return the figure - #29

Merged
javoha merged 1 commit into
mainfrom
jvh/plot-2d-axes
Dec 4, 2026
Merged

javoha merged 1 commit into
mainfrom
jvh/plot-2d-axes

Conversation

@javoha

@javoha javoha commented Dec 3, 2026

Copy link
Copy Markdown
Member

What

All matplotlib 2D plots of the Workbench can now draw into existing axes and skip showing the figure, and they return the figure and axes. This is the same pattern as the 3D plots, which already take show and return their plotter.

Function Workbench component New options
plot_structural_model_2D Plot Model Result 2D ax, show → (fig, ax)
plot_fault_model_2D Plot Fault Model Result 2D ax, show → (fig, ax)
plot_cross_section_2D Plot Cross Section 2D axes (two, one per panel), show → (fig, axes)
plot_cross_section_difference_2D (Python only) ax, show → (fig, ax)
plot_variable_along_line Plot Variable Along Line ax, show → (fig, ax)
plot_variable_time_series Plot Variable Time Series ax, show → (fig, ax)

Why

Without this, users can't combine our 2D plots with their own matplotlib content. Two examples:

  • a model section drawn on top of an outcrop photo;
  • several interpolation methods compared in one subplot grid.

A student's example notebooks do both. They relied on a local edit of plot_structural_model_2D on her branch, and a later merge of main dropped that edit, so the notebooks broke. With this PR her calls (fig, ax = plot_structural_model_2D(..., show=False) and ax=ax, show=False) work as written.

Details

  • Defaults unchanged: without ax/show, each plot still opens a new figure and shows it. The Workbench inspectors ignore the return value, so they behave as before.
  • Layout: a figure the plot creates itself is laid out as before (tight_layout). When the caller passes an axes, arranging the figure is left to the caller.
  • Shared helpers: figure_and_axes and finish_figure live in the new core/utility/figures.py.
  • No more drawing on the current figure: plot_variable_along_line and the fault-domain colourbar of plot_fault_model_2D used pyplot's current figure. They now draw on their own figure/axes, so they no longer end up on the wrong figure when ax is given.
  • Not changed: the developer debug plots StructuralFrame.plot_scalar_field_section / plot_age_mask_section and the matplotlib plots in the meshing code. They are not Workbench plots.
  • Manuals: the structural and simulation manuals list the options. The structural manual has examples for an image overlay and for side-by-side models.

Tests

  • New tests check:
    • the structural and fault 2D plots draw into the subplots of a given figure;
    • all four simulation 2D plots draw into the subplots of a given figure;
    • show=False does not show the figure;
    • the default still makes its own figure and shows it;
    • plot_cross_section_2D refuses an axes list that doesn't have exactly two axes.
  • Locally, the 2D plot, structural visualization and simulation Workbench component tests pass, as do the component signature and palette checks (164 passed).
  • I stopped the local full suite early; CI runs it.

🤖 Generated with Claude Code

All matplotlib 2D plots of the Workbench take ax (axes to draw into,
e.g. one subplot) and show (False: return without showing, to add to
the plot first), and return (fig, ax), like the 3D plots already take
show and return their plotter:

- plot_structural_model_2D, plot_fault_model_2D
- plot_cross_section_2D (axes: two axes, one per panel; returns
  (fig, axes)), plot_cross_section_difference_2D
- plot_variable_along_line, plot_variable_time_series

Defaults are unchanged (new figure, shown), so the Workbench inspectors
behave as before. A figure the plot creates is laid out as before; a
caller's figure is left for the caller to arrange. Shared helpers in
core/utility/figures.py. Along-line and fault-domain colorbar no longer
use pyplot's current figure.

Use case: model sections drawn on top of an outcrop photo, and method
comparisons in one subplot grid (a student's notebooks needed a local
backend change for this, which a later merge dropped).

Manuals list the options with examples; tests cover drawing into given
axes, show=False and the default.

Co-Authored-By: Claude Opus 5.5
@javoha
javoha requested review from a team as code owners December 3, 2026 14:43
@javoha
javoha requested a review from luepges December 3, 2026 14:43
@javoha
javoha merged commit 099516a into main Dec 4, 2026
4 checks passed
@javoha
javoha deleted the jvh/plot-2d-axes branch December 4, 2026 07:25
javoha added a commit that referenced this pull request Dec 4, 2026
Brings in #29 (2D plots: ax, show, return the figure). Conflicts in the
cross-section plots: keep the plane titles of this branch with the
show/return of main; tests: keep both.

Co-Authored-By: Claude Opus 5.5
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