Subplot

Dear everyone, I am a beginner in Gmt. This is the code I wrote :

import pandas as pd
import pygmt
fig = pygmt.Figure()

df1 = pd.read_csv (‘data1.csv’,sep=‘;’)
df2 = pd.read_csv (‘data2’, sep=‘;’)
#Définition de la Région d’étude
region=[12.7,15.3,3,6.5]

Interpolation par la méthode de courbure minimale, Tension = 0

grid1 = pygmt.surface(data=df1, region=region, spacing=0.0089, tension=0)
grid2 = pygmt.surface(data=df2, region=region, spacing=0.0089, tension=0)

#Définir la palette de couleurs
pygmt.makecpt(cmap=“rainbow”, series=[-120, -12, 4])

#Définition du subplot 1 ligne et 2 colonnes
with fig.subplot(
nrows=1,
ncols=2,
figsize=(“12c”),
autolabel=True,
sharex=“b”, # shared x-axis on the bottom side
sharey=“l”, # shared y-axis on the left side
frame=[“WSne”],
margins=[“6.5c”],
):

#Première carte
    fig.basemap(region=region, projection="U33N/12c", panel=0)
    #Représentation de la carte des anomalies de Bouguer XGMe_2019
    fig.grdimage(grid=grid1, region=region, projection="U33N/12c", 
                 cmap=True, panel=[0, 0])
    #Ajout de l'échelle : Transparence 30, contour noirgris (gray30) épaisseur 0.5
    # Cadre de forme arrondis 
    fig.basemap (frame=['lSENt', "xa0.2", "ya0.1"], 
                map_scale="jBL+o1c/1c+c-7+w50k+f+lkm+ar",
                box="+gwhite@30+p0.5p,gray30,solid+r3p",)

    #Ajout de la barre des couleurs
    fig.colorbar(position="JML+o0.5c/0c+w12c/0.5c", 
                 frame=["xa5f2+lAnomalies de Bouguer", "y+lmGal"])
    
    #Seconde carte
    fig.basemap(region=region, projection="U33N/12c", panel=1)
    #Représentation de la carte des anomalies de Bouguer EIGEN6C4
    fig.grdimage(grid=grid2, region=region, projection="U33N/12c", 
                 cmap=True)
   
    #Ajout de l'échelle : Transparence 30, contour noirgris (gray30) épaisseur 0.5
    # Cadre de forme arrondis 
    fig.basemap (frame=['lSENt', "xa0.2", "ya0.1"], 
                 map_scale="jBL+o1c/1c+c-7+w50k+f+lkm+ar",
                 box="+gwhite@30+p0.5p,gray30,solid+r3p",)
    
    fig.show()

When using the subplot option to draw my maps, I can’t properly set up the options for an optimal display of my map, including figsize=(“12c”), fig.basemap (xxxxx). Here is the result it displays, can you help me?

Hi there, I’m by no means an expert at GMT either, so, if someone comes along and provides a better explanation, I’d follow theirs.

I set up my subplots as follow:

GMT.subplot(grid = "2x1", panels_size=8);

Where I’ll define how I want my grid to be set up & the size of my panels – the panel size just takes a few iterations to see which fits best for your usage.

Then, below, I’ll copy an paste and example that I am utilizing currently.

GMT.basemap(region= [-130 -70 24 51], proj = (name = :lambertConic, center = [-100 35], parallels = [33 45]),
    coast = (borders = ((type = 1, pen = ("thick", "black")), (type = 2, pen = ("thinner", "lightgrey"))),
        area = 500,
        shore = (:thinnest, :lightgrey)),
    panel = (1,1),
    title = "Vertical Displacement | $yr"
);

GMT.basemap(region = [-130 -70 24 51],
    proj = (name = :lambertConic, center = [-100 35], parallels = [33 45]),
    coast = (borders = ((type = 1, pen = ("thick", "black")), (type = 2, pen = ("thinner", "lightgrey"))),
        area = 500,
        shore = (:thinnest, :lightgrey)),
    panel = (2,1),
    title = "Eastward Displacement | $yr"
);

Where in each plot, I’ll define which panel I want the plot to be designated. I don’t know if this is exactly what you were looking for, but hopefully it will give some kind of structural guidance. Note that my code is from Julia, not Python, so usage may vary.

But the output after I am done looks something like this – albeit an older example, but the general structure of my code above is the same: