Skip to content

fix: PNG backend twin axes top-axis tick label overlaps plot title (fixes #1700)#1822

Merged
krystophny merged 1 commit intomainfrom
fix/issue-1700-twin-axes-title-overlap
Apr 26, 2026
Merged

fix: PNG backend twin axes top-axis tick label overlaps plot title (fixes #1700)#1822
krystophny merged 1 commit intomainfrom
fix/issue-1700-twin-axes-title-overlap

Conversation

@krystophny
Copy link
Copy Markdown
Collaborator

Summary

When twiny() creates a secondary x-axis at the top of the plot, the figure title was rendered at a fixed vertical offset from the plot area boundary, causing it to overlap with the top-axis tick labels and the top xlabel ("Cumulative index (log scale)").

The fix modifies compute_title_position_sized in fortplot_raster_labels.f90 to account for last_x_tick_max_height_top (set by raster_draw_x_axis_ticks_top) when positioning the title. When twiny is active (indicated by last_x_tick_max_height_top > 0), the title is placed above the top xlabel rather than at the fixed offset.

Changes

  • src/backends/raster/fortplot_raster_labels.f90: Added top_tick_height parameter to compute_title_position_sized and compute_title_position. When top_tick_height > 0, the title y position is computed to sit above the top-axis xlabel.
  • test/test_title_position_twiny.f90: New regression test verifying title positioning with and without twiny.

Verification

Test passes after fix

$ fpm test --target test_title_position_twiny
 PASS: Title positioned correctly with and without twiny

$ fpm test --target test_title_centering_raster
 PASS: Title centering matches expected pixel position

$ fpm test 2>&1 | grep -c "PASS:"
827  (all tests pass, no failures)

$ make verify-artifacts
Artifact verification passed.

Artifact evidence

  • output/example/fortran/twin_axes_demo/twin_axes_demo.png (49299 bytes) regenerated with fix
  • output/example/fortran/twin_axes_demo/twin_axes_demo.pdf (6246 bytes) regenerated with fix
  • Text output confirms title and top xlabel render at distinct positions:
    Twin axis demo
    +--------------------------------------------------------------------------------+
    |      1                                Cumulative index (log scale)             |
    

When twiny creates a secondary x-axis at the top, the title was
rendered at a fixed offset from the plot area, causing overlap
with the top-axis tick labels and xlabel. The title position now
accounts for last_x_tick_max_height_top to place the title above
the top-axis elements when twiny is active.
@krystophny krystophny merged commit 96f77fd into main Apr 26, 2026
5 checks passed
@krystophny krystophny deleted the fix/issue-1700-twin-axes-title-overlap branch April 26, 2026 03:46
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.

1 participant