Skip to content

fix: route hist/bar/scatter to active subplot (#2021)#2022

Merged
krystophny merged 1 commit into
mainfrom
fix/2021-subplot-hist-bar-scatter
Jun 15, 2026
Merged

fix: route hist/bar/scatter to active subplot (#2021)#2022
krystophny merged 1 commit into
mainfrom
fix/2021-subplot-hist-bar-scatter

Conversation

@krystophny

Copy link
Copy Markdown
Collaborator

Closes #2021.

Problem

Switching a plotting call from plot(x, y) to hist, bar, barh, or
scatter inside a subplot grid produced blank white axes: the figure
compiled and ran without error, but no data appeared.

Root cause: plot() routes into the selected subplot via subplot_plot,
while hist/bar/scatter build their plot_data into the figure-level
plots array. When a subplot grid is active the renderer draws the subplot
cells and never touches the figure-level array, so that data silently
vanishes.

Fix

Add figure_t%relocate_last_plot_to_subplot, which mirrors the most
recently added figure-level plot into the active subplot, and call it from
the hist, bar/barh (bar_impl/barh_impl), and scatter
(scatter_2d_dispatch) chokepoints. The figure-level slot is retained
rather than removed because the add routines assume monotonically growing
slots; the figure-level array is inert while a subplot grid is active.

Verification

Build (serial to avoid the unrelated fpm parallel-build SIGABRT):

OMP_NUM_THREADS=1 fpm build

Regression test (extends test/state/test_stateful_subplots_routing.f90)

Failing before the fix:

$ fpm test --target test_stateful_subplots_routing
 Running stateful subplot routing tests...
   FAIL: hist not routed to subplot (1,1)
STOP 1

Passing after the fix:

$ fpm test --target test_stateful_subplots_routing
 Running stateful subplot routing tests...
 All stateful subplot routing tests PASSED!

The test asserts hist, bar, and scatter each land in the selected
subplot (subplot_plot_count == 1) and do not leak into the others.

Rendering gate

$ OMP_NUM_THREADS=1 make verify-artifacts
...
[png] subplots_grid_demo.png size=44465
Artifact verification passed.

Reproduced the issue's 2x2 grid (hist / bar / scatter / plot) to
/tmp/repro_2021.pdf. pdftotext -layout shows every cell now carries
data-derived tick ranges instead of the blank 0.0-1.0 default:

hist  (top-left):    x 1.0..5.0,  y 0..4
bar   (top-right):   x 0..20,     y 0..5
scatter (bottom-left): x 2.5..20, y 1..5
plot  (bottom-right):  x 2.5..20, y 1..5

Full test suite passes (OMP_NUM_THREADS=1 fpm test; no test reports FAIL).

plot() routes into the selected subplot via subplot_plot, but hist, bar,
barh, and scatter built their plot_data into the figure-level plots array.
When a subplot grid is active that array is never rendered, so those
commands produced blank axes with no error.

Add figure_t%relocate_last_plot_to_subplot, which mirrors the most recent
figure-level plot into the active subplot, and call it from the hist, bar,
barh, and scatter facade chokepoints. The figure-level slot is retained
(not removed) because the add routines assume monotonically growing slots;
the figure-level array is inert while a subplot grid is active.
@krystophny krystophny merged commit 83cb2fd into main Jun 15, 2026
6 checks passed
@krystophny krystophny deleted the fix/2021-subplot-hist-bar-scatter branch June 15, 2026 13:24
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.

hist(), bar() und scatter() erstellen nichts? Oder unterscheiden sich grundlegend von plot(), in diesem Fall bitte entsprechend dokumentieren.

1 participant