fix: PNG backend twin axes top-axis tick label overlaps plot title (fixes #1700)#1822
Merged
krystophny merged 1 commit intomainfrom Apr 26, 2026
Merged
Conversation
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.
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
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_sizedinfortplot_raster_labels.f90to account forlast_x_tick_max_height_top(set byraster_draw_x_axis_ticks_top) when positioning the title. When twiny is active (indicated bylast_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: Addedtop_tick_heightparameter tocompute_title_position_sizedandcompute_title_position. Whentop_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
Artifact evidence
output/example/fortran/twin_axes_demo/twin_axes_demo.png(49299 bytes) regenerated with fixoutput/example/fortran/twin_axes_demo/twin_axes_demo.pdf(6246 bytes) regenerated with fix