Skip to content

Fit 3-D subplot panels, and their heading, inside the figure (#4450) - #9152

Open
joa-quim wants to merge 1 commit into
masterfrom
issue-4450
Open

Fit 3-D subplot panels, and their heading, inside the figure (#4450)#9152
joa-quim wants to merge 1 commit into
masterfrom
issue-4450

Conversation

@joa-quim

@joa-quim joa-quim commented Aug 26, 2026

Copy link
Copy Markdown
Member

A perspective panel is drawn as a projected box that is larger than the flat map rectangle subplot lays its panels out from, and nothing ever fitted that box to the panel. In the reported example both cubes burst out of the -Ff20c/10c figure area and the heading was laid out against the flat rectangle, so it ended up among them.

gmt_map_setup could not have fitted the box earlier: it is only known once gmtmap_init_three_D has run, at the very end of the setup. So the fit now happens there, for a panel in 3-D: the footprint is measured from the eight corners of the x/y/z region, padded for the ticks and annotations that the frame draws outside it (a quarter of that above the box, where nothing is annotated), and if it does not fit the panel the projection is scaled down and the box centered in the panel via z_project.x_off/y_off. The scaling includes proj.zmax/zmin, the z-axis length in plot units that the PostScript perspective matrix works from; without those the numbers changed but the picture did not.

The heading is now placed at subplot end rather than at subplot begin, since only then is it known how far a 3-D panel reaches: begin records the position it would have used in gmt.subplotheading. together with the canvas corner (as PSL_SUBPLOT_ox/oy in the PostScript, so no assumption about -X -Y is needed), gmt_plotinit records the highest projected y of any 3-D panel in gmt.subplottop., and end returns to that corner, raises the heading by any excess and puts the origin back for whatever follows. The panel settings are cleared around that call, or the heading is scaled into the last panel, and restored afterwards since the -R history is built from them.

test/subplot/subplot_3d_fit.sh plots the example from the issue and requires the drawn height to stay near the 10 cm of the figure; the unfitted cubes reach some 19 cm. It measures the plot instead of comparing it, so it needs no baseline PostScript.

Fix #4450

Assisted-by: Claude Opus 5.0 But it resisted like hell to fix this.

The issue's example now produces.
issue4450

A perspective panel is drawn as a projected box that is larger than the flat
map rectangle subplot lays its panels out from, and nothing ever fitted that
box to the panel.  In the reported example both cubes burst out of the
-Ff20c/10c figure area and the heading was laid out against the flat rectangle,
so it ended up among them.

gmt_map_setup could not have fitted the box earlier: it is only known once
gmtmap_init_three_D has run, at the very end of the setup.  So the fit now
happens there, for a panel in 3-D: the footprint is measured from the eight
corners of the x/y/z region, padded for the ticks and annotations that the
frame draws outside it (a quarter of that above the box, where nothing is
annotated), and if it does not fit the panel the projection is scaled down and
the box centered in the panel via z_project.x_off/y_off.  The scaling includes
proj.zmax/zmin, the z-axis length in plot units that the PostScript perspective
matrix works from; without those the numbers changed but the picture did not.

The heading is now placed at subplot end rather than at subplot begin, since
only then is it known how far a 3-D panel reaches: begin records the position
it would have used in gmt.subplotheading.<fig> together with the canvas corner
(as PSL_SUBPLOT_ox/oy in the PostScript, so no assumption about -X -Y is
needed), gmt_plotinit records the highest projected y of any 3-D panel in
gmt.subplottop.<fig>, and end returns to that corner, raises the heading by any
excess and puts the origin back for whatever follows.  The panel settings are
cleared around that call, or the heading is scaled into the last panel, and
restored afterwards since the -R history is built from them.

2-D figures write no gmt.subplottop file and are unaffected; test/subplot is
unchanged apart from the new test.

test/subplot/subplot_3d_fit.sh plots the example from the issue and requires
the drawn height to stay near the 10 cm of the figure; the unfitted cubes reach
some 19 cm.  It measures the plot instead of comparing it, so it needs no
baseline PostScript.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@joa-quim
joa-quim requested a review from a team August 26, 2026 19:17
@joa-quim joa-quim added the AI-assisted All (or most) of the code was written by Artificial Intelligence. label Aug 26, 2026

@Esteban82 Esteban82 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-assisted All (or most) of the code was written by Artificial Intelligence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3D subplot title positioning doesn't account for perspective angle

2 participants