Examples

The gmtplot directive supports any GMT versions, and both Bash and Python scripts.

Classic GMT bash script

The following RST code:

.. gmtplot::
    :language: bash
    :caption: Example showing how to include GMT figures with inline codes

    ps=example_05.ps
    gmt grdmath -R-15/15/-15/15 -I0.3 X Y HYPOT DUP 2 MUL PI MUL 8 DIV COS EXCH NEG 10 DIV EXP MUL = sombrero.nc
    gmt makecpt -C128 -T-5,5 -N > g.cpt
    gmt grdview sombrero.nc -JX6i -JZ2i -B5 -Bz0.5 -BSEwnZ -N-1+gwhite -Qs -I+a225+nt0.75 -X1.5i \
        -Cg.cpt -R-15/15/-15/15/-1/1 -K -p120/30 > $ps
    echo "4.1 5.5 z(r) = cos (2@~p@~r/8) @~\327@~e@+-r/10@+" | gmt pstext -R0/11/0/8.5 -Jx1i \
            -F+f50p,ZapfChancery-MediumItalic+jBC -O >> $ps
    rm -f g.cpt sombrero.nc

is executed by sphinx and turned into:

ps=example_05.ps
gmt grdmath -R-15/15/-15/15 -I0.3 X Y HYPOT DUP 2 MUL PI MUL 8 DIV COS EXCH NEG 10 DIV EXP MUL = sombrero.nc
gmt makecpt -C128 -T-5,5 -N > g.cpt
gmt grdview sombrero.nc -JX6i -JZ2i -B5 -Bz0.5 -BSEwnZ -N-1+gwhite -Qs -I+a225+nt0.75 -X1.5i \
        -Cg.cpt -R-15/15/-15/15/-1/1 -K -p120/30 > $ps
echo "4.1 5.5 z(r) = cos (2@~p@~r/8) @~\327@~e@+-r/10@+" | gmt pstext -R0/11/0/8.5 -Jx1i \
        -F+f50p,ZapfChancery-MediumItalic+jBC -O >> $ps
rm -f g.cpt sombrero.nc
_images/345544d6a7f3a553c55268e0a12efdcb.png

Example showing how to include GMT figures with inline codes

Modern GMT bash script

We have a modern-mode GMT bash script modern-gmt.sh in the examples/ directory. Its content is:

gmt begin GMT_orthographic
    gmt coast -Rg -JG-75/41/12c -Bg -Dc -A5000 -Gpink -Sthistle
gmt end show

The following ReST code:

.. gmtplot:: examples/modern-gmt.sh
    :width: 30%
    :caption: GMT Orthographic projection

is executed by sphinx and turned into:

gmt begin GMT_orthographic
    gmt coast -Rg -JG-75/41/12c -Bg -Dc -A5000 -Gpink -Sthistle
gmt end show
_images/00524c4cc35b55773ac5dfa554eb7b31.png

Data files

If your GMT script needs data files, you can put data files under the same directory as the GMT script (or the ReST file for inline codes). Or you can put data files in directories defined by environmental variable GMT_DATADIR.

In this example, the script is examples/needs-data-files.sh, and the data file is examples/points.txt.

The following ReST code:

.. gmtplot:: examples/needs-data-files.sh
    :width: 50%
    :caption: GMT script needs a data file.

is executed by sphinx and turned into:

gmt begin datapoints
	gmt plot points.txt -Sc0.4c -Gred -JX10c/5c -Baf
gmt end show
_images/c7a1b6ed76677430c5b56ca3dfe6c243.png