Demo of the gmt-python package for Scipy 2017.
Try to recreate a few plots from the GMT Tutorial.
import gmt
Importing the module starts a mordern mode session. So there is no need to call gmt begin
and gmt end
.
GMT creates a temporary directory where everything is stored.
ls -d /tmp/gmt*
/tmp/gmt6.26664/
Start a new figure.
gmt.figure()
Copy and modify some code from the tutorial:
gmt pscoast -R-90/-70/0/20 -JM6i -P -Ba -Gchocolate > GMT_tut_3.ps
gmt.pscoast(R='-90/-70/0/20', J="M6i", G='chocolate', B='a', P=True)
View the plot in the notebook:
gmt.show()
Use aliases for the command-line arguments.
help(gmt.pscoast)
Help on function pscoast in module gmt.ps_modules: pscoast(**kwargs) Plot continents, shorelines, rivers, and borders on maps Plots grayshaded, colored, or textured land-masses [or water-masses] on maps and [optionally] draws coastlines, rivers, and political boundaries. Alternatively, it can (1) issue clip paths that will contain all land or all water areas, or (2) dump the data to an ASCII table. The data files come in 5 different resolutions: (**f**)ull, (**h**)igh, (**i**)ntermediate, (**l**)ow, and (**c**)rude. The full resolution files amount to more than 55 Mb of data and provide great detail; for maps of larger geographical extent it is more economical to use one of the other resolutions. If the user selects to paint the land-areas and does not specify fill of water-areas then the latter will be transparent (i.e., earlier graphics drawn in those areas will not be overwritten). Likewise, if the water-areas are painted and no land fill is set then the land-areas will be transparent. A map projection must be supplied. Full option list at http://gmt.soest.hawaii.edu/doc/latest/pscoast.html **Aliases:** - A = area_thresh - B = frame - D = resolution - G = land - I = rivers - J = projection - N = borders - P = portrait - R = region - S = water - W = shorelines Parameters ---------- J : str *Required if this is the first plot command*. Select map projection. R : str or list *Required if this is the first plot command*. ``'xmin/xmax/ymin/ymax[+r][+uunit]'``. Specify the region of interest. A : int, float, or str ``'min_area[/min_level/max_level][+ag|i|s|S][+r|l][+ppercent]'`` Features with an area smaller than min_area in km^2 or of hierarchical level that is lower than min_level or higher than max_level will not be plotted. B : str Set map boundary frame and axes attributes. C : str Set the shade, color, or pattern for lakes and river-lakes. D : str Selects the resolution of the data set to use ((f)ull, (h)igh, (i)ntermediate, (l)ow, and (c)rude). G : str Select filling or clipping of “dry” areas. I : str ``'river[/pen]'`` Draw rivers. Specify the type of rivers and [optionally] append pen attributes. N : str ``'border[/pen]'`` Draw political boundaries. Specify the type of boundary and [optionally] append pen attributes S : str Select filling or clipping of “wet” areas. U : bool or str Draw GMT time stamp logo on plot. W : str ``'[level/]pen'`` Draw shorelines [Default is no shorelines]. Append pen attributes.
gmt.figure()
gmt.pscoast(region='-90/-70/0/20', projection="M6i",
land='chocolate', frame='a', portrait=True)
gmt.show()
We automatically convert some arguments for you.
Let's look at another command:
gmt pscoast -R-130/-70/24/52 -JB-100/35/33/45/6i -Ba -B+t"Conic Projection" -N1/thickest -N2/thinnest -A500 -Ggray -Wthinnest -P > GMT_tut_4.ps
gmt.figure()
gmt.pscoast(region=[-130, -70, 24, 52], projection="B-100/35/33/45/6i",
land='gray', frame='a', portrait=True, shorelines='thinnest',
borders='1/thickest', area_thresh=500)
gmt.show()
Lets plot some data!
This example will not work entirely yet:
gmt makecpt -Cred,green,blue -T0,70,300,10000 > quakes.cpt
gmt pscoast -R130/150/35/50 -JM6i -B5 -P -Ggray -K > GMT_tut_9.ps
gmt psxy -R -J -O @tut_quakes.ngdc -Wfaint -i4,3,5,6s0.1 -h3 -Scc -Cquakes.cpt >> GMT_tut_9.ps
gmt.figure()
gmt.pscoast(region=[130, 150, 35, 50], projection='M6i', frame=5, portrait=True, land='gray')
gmt.psxy(data='@tut_quakes.ngdc', pen='faint', i='4,3', style='c0.2c', color='blue')
gmt.show()
Save the figure to file:
gmt.psconvert(prefix='my_figure', fmt='g', crop=True)
ls *.png
my_figure.png