# Issue with tick labels staying outside frame \[PYGMT\]

**URL:** <https://forum.generic-mapping-tools.org/t/issue-with-tick-labels-staying-outside-frame-pygmt/5604>\
**Category:** PyGMT Q&A\
**Created:** [December 6, 2024, 6:36pm UTC](https://forum.generic-mapping-tools.org/t/issue-with-tick-labels-staying-outside-frame-pygmt/5604 "2024-12-06T18:36:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robson](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@Robson](https://forum.generic-mapping-tools.org/u/Robson)\
**Post date:** [December 6, 2024, 6:36pm UTC](https://forum.generic-mapping-tools.org/t/issue-with-tick-labels-staying-outside-frame-pygmt/5604/1 "2024-12-06T18:36:19Z")

</div>

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:

```auto
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()

```

 ![Teste](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/f/f724b6099f41f7c508e04f9c3efeee0bddcec3d4.png)

Thank you in advance

---

<div class="post-metadata">

**Author:** ![Esteban82](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/esteban82/32/54_2.png) [@Esteban82](https://forum.generic-mapping-tools.org/u/Esteban82)\
**Post date:** [December 6, 2024, 8:10pm UTC](https://forum.generic-mapping-tools.org/t/issue-with-tick-labels-staying-outside-frame-pygmt/5604/2 "2024-12-06T20:10:24Z")

</div>

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](https://docs.generic-mapping-tools.org/6.5/gmt.html#b-full).

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.

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [December 6, 2024, 10:30pm UTC](https://forum.generic-mapping-tools.org/t/issue-with-tick-labels-staying-outside-frame-pygmt/5604/3 "2024-12-06T22:30:35Z")

</div>

> [@Esteban82](#):
>
> skip annotations that fall exactly at the ends of the axis

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

---

<div class="post-metadata">

**Author:** ![Robson](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@Robson](https://forum.generic-mapping-tools.org/u/Robson)\
**Post date:** [December 9, 2024, 12:55pm UTC](https://forum.generic-mapping-tools.org/t/issue-with-tick-labels-staying-outside-frame-pygmt/5604/4 "2024-12-09T12:55:42Z")

</div>

> [@mkononets](#):
>
> range aligned with half of his tick interval

@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.

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [December 9, 2024, 3:14pm UTC](https://forum.generic-mapping-tools.org/t/issue-with-tick-labels-staying-outside-frame-pygmt/5604/5 "2024-12-09T15:14:45Z")

</div>

assuming your tick interval is 1000:

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

```

same for x.

---

<div class="post-metadata">

**Author:** ![Robson](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@Robson](https://forum.generic-mapping-tools.org/u/Robson)\
**Post date:** [December 9, 2024, 5:46pm UTC](https://forum.generic-mapping-tools.org/t/issue-with-tick-labels-staying-outside-frame-pygmt/5604/6 "2024-12-09T17:46:38Z")

</div>

Thank you, I will implement it in my code.

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [December 9, 2024, 5:56pm UTC](https://forum.generic-mapping-tools.org/t/issue-with-tick-labels-staying-outside-frame-pygmt/5604/7 "2024-12-09T17:56:38Z")

</div>

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:

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

```
