# Subplot

**URL:** <https://forum.generic-mapping-tools.org/t/subplot/5557>\
**Category:** PyGMT Q&A\
**Created:** [November 25, 2024, 5:48pm UTC](https://forum.generic-mapping-tools.org/t/subplot/5557 "2024-11-25T17:48:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TFJospin](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@TFJospin](https://forum.generic-mapping-tools.org/u/TFJospin)\
**Post date:** [November 25, 2024, 5:48pm UTC](https://forum.generic-mapping-tools.org/t/subplot/5557/1 "2024-11-25T17:48:12Z")

</div>

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?

 ![Figure 2024-11-25 183405](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/5/57b9d13b5c4e78eca08769ac9f6ee36dd172e068.png)

---

<div class="post-metadata">

**Author:** ![GeodeticR](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/geodeticr/32/4195_2.png) [@GeodeticR](https://forum.generic-mapping-tools.org/u/GeodeticR)\
**Post date:** [November 25, 2024, 8:33pm UTC](https://forum.generic-mapping-tools.org/t/subplot/5557/2 "2024-11-25T20:33:46Z")

</div>

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:

```auto
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.

```auto
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:

 ![GMTplot](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/7/7f50ae84f8fb2dd2447e884beed3fff1ef302585.png)
