# Irregular subplots plotting in PyGMT

**URL:** <https://forum.generic-mapping-tools.org/t/irregular-subplots-plotting-in-pygmt/4194>\
**Category:** PyGMT Q&A\
**Created:** [August 20, 2023, 2:25am UTC](https://forum.generic-mapping-tools.org/t/irregular-subplots-plotting-in-pygmt/4194 "2023-08-20T02:25:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wensentry](https://avatars.discourse-cdn.com/v4/letter/w/fbc32d/32.png) [@wensentry](https://forum.generic-mapping-tools.org/u/wensentry)\
**Post date:** [August 20, 2023, 2:26am UTC](https://forum.generic-mapping-tools.org/t/irregular-subplots-plotting-in-pygmt/4194/1 "2023-08-20T02:26:00Z")

</div>

Hello everyone,

Can pygmt plot such subplots, with a different number of subgraphs per line, with a legend on the right side of each line and annotations on the left side.

 ![可视化](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/2/2614c93eeea10c61a6626fdfb860059d8b2b55ce.jpeg)

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![weiji14](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/weiji14/32/33_2.png) [@weiji14](https://forum.generic-mapping-tools.org/u/weiji14)\
**Post date:** [August 21, 2023, 3:18am UTC](https://forum.generic-mapping-tools.org/t/irregular-subplots-plotting-in-pygmt/4194/2 "2023-08-21T03:18:27Z")

</div>

Yes it should be possible, see the tutorial at [https://www.pygmt.org/v0.9.0/tutorials/advanced/subplots.html](https://www.pygmt.org/v0.9.0/tutorials/advanced/subplots.html). Use `with fig.subplot(nrows=4, ncols=4, ...)`, and then just skip plotting the row/col panels that you don’t have data for. See also [https://www.pygmt.org/v0.9.0/gallery/embellishments/colorbars\_multiple.html](https://www.pygmt.org/v0.9.0/gallery/embellishments/colorbars_multiple.html) for an example on plotting different colorbars for different panels in a subplot.

---

<div class="post-metadata">

**Author:** ![wensentry](https://avatars.discourse-cdn.com/v4/letter/w/fbc32d/32.png) [@wensentry](https://forum.generic-mapping-tools.org/u/wensentry)\
**Post date:** [August 21, 2023, 6:41am UTC](https://forum.generic-mapping-tools.org/t/irregular-subplots-plotting-in-pygmt/4194/3 "2023-08-21T06:41:20Z")

</div>

@weiji14, Thank you very much for the reply, which is quite useful!

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 11, 2026, 1:39am UTC](https://forum.generic-mapping-tools.org/t/irregular-subplots-plotting-in-pygmt/4194/4 "2026-02-11T01:39:23Z")

</div>

Reviving this. Guys, do you manage to do subplots with colorbars in each panel?

I can’t in GMT.jl and the failure is strange. At the PS level it seems that the origin is always reset before the `gmt colorbar` call and hence the multiple colorbars overlap on top of first one.

---

<div class="post-metadata">

**Author:** ![EvanPi](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@EvanPi](https://forum.generic-mapping-tools.org/u/EvanPi)\
**Post date:** [February 11, 2026, 2:09pm UTC](https://forum.generic-mapping-tools.org/t/irregular-subplots-plotting-in-pygmt/4194/5 "2026-02-11T14:09:25Z")

</div>

I think I had a similar problem a while ago and I solved it by specifying the region and projection (`-R` and `-J`) in the colorbar.

```auto
gmt inset begin -R105.2W/104.6W/4.75S/4.4S -JM3i -DJLB+o-5.25i/0.4i -F+gwhite+p0.5p,black -N
gmt makecpt -Chaxby -T-5000/-2000 -H > haxby.cpt
gmt basemap -Bpxa0.2 -Bpya0.1 -LjLT+o0.2+w10k+l"Scale (km)" -BSEnw \
            --MAP_FRAME_TYPE=inside --MAP_FRAME_AXES=eslt --FORMAT_GEO_MAP=ddd.x
gmt colorbar -Chaxby.cpt -DJCB+w2.6i/0.1i+o0.0i/0.25i+h+ml -Bxa1000f250+l"Bathymetry Depth" -By+lm -Vd -R105.2W/104.6W/4.75S/4.4S -JM3i
rm -f haxby.cpt
gmt inset end

```

If you do not specify `-R` and `-J` in `gmt colorbar`, then the colorbar scale plots out of alignment.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [February 12, 2026, 12:20am UTC](https://forum.generic-mapping-tools.org/t/irregular-subplots-plotting-in-pygmt/4194/6 "2026-02-12T00:20:10Z")

</div>

Thanks, but the case I’m referring to is different. It’s some convoluted missing set occurring when calling GMT from _externals_ (Julia/Matlab in this case) to make subplots figures.
