Issue with tick labels staying outside frame [PYGMT]

Hello everyone,

I’m plotting hundreds of maps using PyGMT, all in Cartesian coordinates. I’m setting the tick labels to be inside the frame using MAP_FRAME_TYPE='inside'. Since there are so many maps, I need this configuration to work automatically without customizing each map individually.

However, I’ve encountered an issue: when I add a title to the map, the tick labels sometimes appear outside the frame (see the example below). If I don’t include a title, the tick labels are clipped and stay within the frame.

Is there a way to ensure the tick labels remain inside the frame, even when adding a title?

Here is a minimal code example to reproduce the issue:

import pygmt

fig = pygmt.Figure()

with pygmt.config(
        MAP_FRAME_TYPE='inside',
        MAP_FRAME_PEN='#333333FF',
        MAP_GRID_PEN_PRIMARY="0.08p,#555555FF@20,--",
        FONT_ANNOT_PRIMARY='6.5p,#333333FF',
        FONT_TITLE='18p',
        MAP_TITLE_OFFSET='3.1p',
        MAP_ANNOT_ORTHO='e',
        MAP_TICK_LENGTH_PRIMARY='1p',
        MAP_ANNOT_OFFSET_PRIMARY='1p',
        PS_PAGE_COLOR='white'):

    fig.basemap(projection='x0.00175', frame=['a1000f1000g1000', '+t Título'], region=[314408.4021, 319608.4021, 8763841.448, 8769041.448])
    
    fig.show()

Thank you in advance

With GMT there is the option to use +e to:

  • +e to give skip annotations that fall exactly at the ends of the axis. Append l or u to only skip the lower or upper annotation, respectively.

Link.

I don’t know if you are already using it. If so, then I think there is no easy solution. Maybe you could try to make the letters smaller.

they mean exactly. annotation that don’t fall exactly at the ends aren’t skipped

for the topic starter it might be the easiest to define the range aligned with half of his tick interval, something like region=[314408.4021, 319608.4021, 8763500, 8769500]
x range boundaries fall fall approximately at the half so no hanging labels

@Esteban82 @mkononets Thank you for the suggestions. Apparently, I will have to follow what @mkononets suggested. However, my maps are centered on a point (x, y), and I have a list with several x and y values. The region is calculated by applying an offset to the coordinates x−2600,x+2600,y−2600,y+2600x-2600, x+2600, y-2600, y+2600x−2600,x+2600,y−2600,y+2600. I do this to ensure that all maps have the same extent in both x and y. Using the suggested approach and aligning the range with half of his tick interval, I’m not sure if I can ensure that each map has the same horizontal and vertical size in meters.

assuming your tick interval is 1000:

y_min = 500*floor((y−2600)/500)
y_max = 500*ceil((y+2600)/500)

same for x.

Thank you, I will implement it in my code.

my quick code is wrong, in a way that it will align y_min/max with 500 and also with 1000 as 1000=2*500. But it can be modified to always provide …500 values.

… or the +e modifier can be used so the exact boundary tick labels will be skipped, but it will look less nice as with the range boundaries aligned in the middle of tick interval:

frame=['+e', 'a1000f1000g1000', '+t Título']