Hi, guys, would you help me find that why my inset pic is not complete, thanks

This is my code:

grid = pygmt.datasets.load_earth_relief(resolution="30s", region=region)
fig = pygmt.Figure()
fig.grdimage(grid=grid, projection="M15c", frame="a", cmap="geo")
#fig.colorbar(frame=["a1000", "x+lElevation", "y+lm"])
fig.colorbar(
    cmap="geo",
    # Colorbar position justified outside map frame (J) at Middle Right (MR),
    # offset (+o) by 1 cm horizontally and 0 cm vertically from anchor point,
    # with a length/width (+w) of 7 cm by 0.5 cm and a box for NaN values (+n)
    position="JMR+o1.1c/0c+w7c/0.5c+n+mc",
    #position="JMR+o1c/0c+w7c/0.5c+n+mc",
    # Note that the label 'Elevation' is moved to the opposite side and plotted
    # vertically as a column of text using '+mc' in the position parameter
    # above
    frame=["x+lElevation", "y+lm"],
    scale=10,
)
pygmt.makecpt(cmap="viridis", series=[min(mag), max(mag)])

# style='c0.1i',

fig.plot(x=lon, 
         y=lat,         
         sizes=0.02 * 2 ** mag,## 少输入's'坑很久!
         color=mag,
         cmap=True,    
         style='cc',      
         pen='black',
         # label='Eq',
        )
fig.colorbar(frame='af+l"Depth (km)"')
# fig.legend(position="JTR+jTR+o0.2c", box=True)

with fig.inset(position="jBL+w5c+o0.5c/0.2c", box="+pblack"):
    # Use a plotting function to create a figure inside the inset
    fig.coast(
        region=[80,110,20,40],
        projection="M5c",
        land="gray",
        borders=[1, 2],
        shorelines="1/thin",
        water="white",
        # Use dcw to selectively highlight an area
        dcw="US.MA+gred",
    )
    rectangle = [[100,32,107,38]]   #顺序不一样
    fig.plot(data=rectangle, style="r+s", pen="2p,blue")
fig.show()

And the pic out is like this:

Hi @Phd.Yin,

Thanks for trying out PyGMT! So the reason you have some blank space in your inset is because you set a square 5cm region when using fig.inset(position="jBL+w5c"), but your region in fig.coast(region=[80,110,20,40] is a rectangle.

To fix your problem, I would suggest 1) change the inset size to be rectangular using position="jBL+w5c/4c, and 2) Change the inset coast projection size to be automatic using `projection=“M?”.

with fig.inset(position="jBL+w5c/4c+o0.5c/0.2c", box="+pblack"):
    # Use a plotting function to create a figure inside the inset
    fig.coast(
        region=[80,110,20,40],
        projection="M?",
        land="gray",
        borders=[1, 2],
        shorelines="1/thin",
        water="white",
        # Use dcw to selectively highlight an area
        # dcw="US.MA+gred",
    )
    rectangle = [[100,32,107,38]]   #顺序不一样
    fig.plot(data=rectangle, style="r+s", pen="2p,blue")

I don’t have your mag data, but the plot should produce something like this:

Let us know if you need any more help :slight_smile:

1 Like

Thanks, this really helpful!