How to show latitude/longitude tick marks for the PyGMT inset figure

I am making the inset figure that shows wide region that contains main figure.

Following basic tutorial that is provided for making inset, I could successfully create one, but I am having trouble showing latitude/longitude grids for the inset figure. I could not find any example related to it, so I am asking here.

My PyGMT version is the latest stable version (v0.6.1).

I attach the code below:


pmt.config(MAP_FRAME_TYPE="plain") # No fancy boundary
pmt.config(FORMAT_GEO_MAP="ddd.x") # Display latitude/longitude upto 1st decimal point

# Set the region to show (latitude/longitude min/max range)
subset_region=[126.5, 129.0, 34.0, 36.2]

fig.basemap(region=subset_region, projection="M15c", frame=["WSne", "xaf", "yaf"])
fig.coast(land="lightgrey", water="lightskyblue", shorelines="1/0.5p", map_scale="n0.85/0.075+l+c127.7/34.95+w50")

with fig.inset(position="jTL+w8.4c/5.6c+o0.5c", box="+p1.5p"):
    # Set the region to show (latitude/longitude min/max range)
    inset_region=[115.0, 150.0, 30.0, 48.0]
    fig.basemap(region=inset_region, projection="M15c", frame=["WSne", "xaf", "yaf"])
    fig.coast(land="lightgrey", water="lightskyblue", borders=["1/0.2p,black"], shorelines="1/0.5p", map_scale="n0.85/0.15+l+c127.7/34.95+w500")

    ###### Box encompassing the large area ######
    rectangle = [[subset_region[0], subset_region[2], subset_region[1], subset_region[3]]]
    fig.plot(data=rectangle, style="r+s", pen="2p,red")  

# fig.savefig(fname="Station_map_tectonic_inset.pdf", dpi=500)

The figure that is currently reproduced is the following:

Is this what you want?

Your script doesn’t work because the layer produced by the coast command covers the layer produced by the basemap comand. So instead of using coast after basemap, you can use a single coast command to draw coastlines and grids at the same time. Try changing your command to this one:

    frame=["WSne", "xafg", "yafg"], 

Thanks for your reply. I think I was not very clear about what I want. I want latitudes and longitudes to show up at the inset boundaries, similar to large figure.
I wonder if this option is implemented by PyGMT.

I attach the example of figure with inset below.

Now I see what you want.

You need to give extra spacing inside the inset box using the margin parameter:

with fig.inset(position="jTL+w8.4c/5.6c+o0.5c", box="+p1.5p+gwhite", margin="0.8c"):

Besides that, you also need to change your projection="M15c" to projection="M?" instead, because the inset dimensions are automatically determined by +w8.4c/5.6c in the position paramter.

I got it! Your solution is very clear.

Thanks a lot!