GeezerVison is showing github.com — Z-axis disappearing issue · Issue #8812 · GenericMappingTools/gmt
Z-axis disappearing issue #8812Labels bugSomething isn't working DescriptionWhy might the Z-axis disappear or become invisible when I change it to a logarithmic scale in a 3D plot, and how can I fix it?
gmt begin rms png E600
R=1e+17/1e+21/1e+17/1e+21/1e5/1e19
gmt basemap -R$R -Jz1cl -BwSEnZ -JX10cl -p130/50 -Bxa1f3p -Bya1f3p -Bza1f3p
R=1e+17/1e+21/1e+17/1e+21/1e10/1e19
gmt basemap -R$R -Jz1cl -BwSEnZ -JX10cl -p130/50 -Bxa1f3p -Bya1f3p -Bza1f3p -X15c
gmt end
 Activityjoa-quim commented on Oct 12, 2025 Please don't use issues to ask questions. Use the forum instead.
The problem is related to -R limits not the logarithmic scale. See, no z axis here either.
gmt basemap -R1e+17/1e+21/1e+17/1e+21/1e10/1e19 -Jz1cl -BwSEnZ -JX10cl -p130/50 -Bxa1f3p -Bya1f3p -Bza1f3p -png lixo
Xiongwei789 commented on Oct 13, 2025 Thanks for your reply. However, when I adjust the z-range in the -R option, for example:
gmt basemap -R1e+17/1e+21/1e+17/1e+21/1e5/1e19 -Jz1cl -BwSEnZ -JX10cl -p130/50 -Bxa1f3p -Bya1f3p -Bza1f3p -png lixo
If I want to plot the z-axis for a different range, such as -R1e+17/1e+21/1e+17/1e+21/1e10/1e19, what should I do? Esteban82 commented on Oct 13, 2025 Hi @Xiongwei789.
Could you please post your question on the GMT forum? The community there is very active and it’s usually the best place to get detailed help. Xiongwei789 commented on Oct 13, 2025 OK. Thank you. I will ask on the GMT forum. Esteban82 commented on Oct 13, 2025 @joa-quim I think there is a bug. When the mininum z value is 1789569 is fine. But if I add 1, (so the zmin is 1789570) then I cannot plot the Z axis.
gmt basemap -R0/1/0/1/1789569/1.79e6 -JZ4c -BwSEnZ -JX10c -p130/50 -Bf -Bza -png lixo # this works
gmt basemap -R0/1/0/1/1789570/1.79e6 -JZ4c -BwSEnZ -JX10c -p130/50 -Bf -Bza -png lixo_bug # Bug. Without z axis.
I get this figure with the second command:
 joa-quim commented on Oct 13, 2025 Nice example. Even before disappearing the vertical axis starts to float away
gmt basemap -R0/1/0/1/1789569.6/1.79e6 -JZ4c -BwSEnZ -JX10c -p130/30 -Bf -Bza -png lixo
 joa-quim commented on Mar 20, 2026 Claude's analysis
● There's the bug! Line 740:
return (PSL->internal.y0 + (int)lrint (y * PSL->internal.y2iy));
psl_iy converts to PS dots using int. When y = -1789569 (the y0 passed to PSL_setorigin for the Z-axis), and y2iy is the conversion from inches to PS
dots (typically 1200 dots/inch):
y * y2iy = -1789569 * 1200 = -2,147,482,800
And INT_MAX = 2,147,483,647 (2^31 - 1). So -1789569 * 1200 = -2,147,482,800 — this is just barely within the 32-bit int range.
But for -1789570 * 1200 = -2,147,484,000 — this overflows a 32-bit int! INT_MIN = -2,147,483,648, so -2,147,484,000 < INT_MIN → integer overflow!
The threshold is exactly INT_MAX / 1200 ≈ 1,789,569.7, which matches the reported boundary between working (1789569) and broken (1789570).
Issue #8812: Root Cause
The bug is a 32-bit integer overflow in postscriptlight.c line 740, in the psl_iy() function:
static int psl_iy (struct PSL_CTRL *PSL, double y) {
return (PSL->internal.y0 + (int)lrint (y * PSL->internal.y2iy));
}
When drawing the Z-axis, gmt_xy_axis is called with y0 = -wesn[ZLO] = -1789569 (raw data units). This gets passed to PSL_setorigin(), which calls
psl_iy(-1789569). With y2iy = 1200 dots/inch:
- lrint(-1789569 * 1200) = lrint(-2,147,482,800) — fits in int (barely)
- lrint(-1789570 * 1200) = lrint(-2,147,484,000) — overflows 32-bit int (INT_MIN = -2,147,483,648)
The overflow threshold is exactly 2^31 / 1200 ≈ 1,789,569.7, matching the reported breakpoint perfectly.
Why is a raw data value being passed as inches?
The deeper issue is in gmt_plot.c line 6844:
gmt_xy_axis (GMT, 0.0, -GMT->common.R.wesn[ZLO], ...)
The y0 = -wesn[ZLO] is passed in data units instead of projected/plot units. For the X and Y axes, gmt_xy_axis receives positions in plot inches, but
for the Z-axis (drawn in a concatenated PS matrix space), the raw data value is used. When ZLO is large, this produces a huge translation that overflows
the PostScript integer coordinate system.
The fix
The y0 for the Z-axis should be computed in projected units (inches) rather than raw data units, or the concat matrix on line 6842 should account for
the offset so that y0 doesn't need to carry a huge data value. Alternatively, psl_iy could use int64_t instead of int, though the PostScript output
format (%d) would also need updating.
MetadataMetadatabugSomething isn't working DevelopmentNo branches or pull requestsIssue actions
|