import pygmt f = open("test.txt", 'w') f.write('0.25 0.75 Say test text\n') f.write('0.5 0.5 two times\n') f.write('0.75 0.25 fast\n') f.close() fig = pygmt.GMT_Figure("output.ps", figure_range='0/1/0/1', projection='X7i', verbosity=4) fig.pstext('', 'test.txt') fig.pstext('', ['0.25 0.7 Say test text', '0.5 0.45 two times', '0.75 0.2 fast']) fig.close()
import pygmt import numpy as np from scipy.special import sph_harm from numpy.random import random_sample #come up with n random points on a sphere n=10000 x = random_sample(n)-0.5 y = random_sample(n)-0.5 z = random_sample(n)-0.5 lats = np.arccos( z/np.sqrt(x*x+y*y+z*z)) lons = np.arctan2( y, x )+np.pi #evaluate a spherical harmonic on that sphere vals = sph_harm(4,9, lons, lats).real vals = vals/np.amax(vals) lons = lons*180.0/np.pi lats = 90.0-lats*180.0/np.pi #recover the spherical harmonic with contouring fig = pygmt.GMT_Figure("output.ps", figure_range='g', projection='G-75/41/7i', verbosity=2) dataset = fig.blockmean('-I5/5 -Rg', [lons,lats,vals]) grid = fig.surface('-I5/5 -Rg', dataset) c = fig.grd2cpt('-Chot', grid, output=None) fig.grdimage('-E100i', grid, cpt=c) fig.grdcontour('-Wthick,black -C0.2', grid) fig.psxy('-Sp.1c', [lons,lats,vals]) fig.close()
import pygmt f = open('gray.cpt', 'w') f.write('-5 128 5 128') f.close() fig = pygmt.GMT_Figure('example_05.ps', verbosity=4) sombrero = fig.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') intens = fig.grdgradient('-A225 -Nt0.75', input=sombrero) fig.grdview('-B5 -Bz0.5 -BSEwnZ -N-1+gwhite -Qs -p120/30 -X1.5i -R-15/15/-15/15 -JX6i -JZ2i', input=sombrero, intensity=intens, cpt='gray.cpt') fig.pstext('-R0/11/0/8. -Jx1i -F+f50p,ZapfChancery-MediumItalic+jBC', [ '4.1 5.5 z(r) = cos (2@~p@~r/8) @~\327@~e@+-r/10@+']) fig.close()
import pygmt ps = 'example_28.ps' fig = pygmt.GMT_Figure(autopilot=False, verbosity=4) kilauea = fig.makecpt('-Ccopper -T0/1500/100 -Z') gradient = fig.grdgradient('-Nt1 -A45', input='Kilauea.utm.nc') fig.grdimage('-Jx1:160000 -P -K --FORMAT_FLOAT_OUT=%%.10g --FONT_ANNOT_PRIMARY=9p ->%s' % ps, input='Kilauea.utm.nc',\ intensity=gradient, cpt=kilauea) fig.pscoast( '-RKilauea.utm.nc -Ju5Q/1:160000 -O -K -Df+ -Slightblue -W0.5p -B5mg5m -BNE \ --FONT_ANNOT_PRIMARY=12p --FORMAT_GEO_MAP=ddd:mmF ->>%s' % ps) fig.psbasemap( ' -R -J -O -K --FONT_ANNOT_PRIMARY=9p -Lf155:07:30W/19:15:40N/19:23N/5k+l1:16,000+u \ --FONT_LABEL=10p ->>%s' % ps) fig.psbasemap( ' -RKilauea.utm.nc+Uk -Jx1:160 -B5g5+u"@:8:000m" -BWSne -O --FONT_ANNOT_PRIMARY=10p \ --MAP_GRID_CROSS_SIZE_PRIMARY=0.1i --FONT_LABEL=10p ->>%s' % ps) fig.close()
import pygmt fig = pygmt.GMT_Figure('example_09.ps', figure_range='185/250/-68/-42', projection='m0.13i', verbosity=4) fig.pswiggle( '-Ba10f5 -BWSne+g240/255/240 -G+red -G-blue -Z2000 -Wthinnest -S240/-67/500/@~m@~rad --FORMAT_GEO_MAP=dddF', input='tracks.txt') fig.psxy('-Wthicker', input='ridge.xy') fig.psxy('-Wthinner', input='fz.xy') fig.gmtconvert('-El', input='tracks.txt', output="tmp.txt") fig.pstext('-F+f10p,Helvetica-Bold+a50+jRM+h -D-0.05i/-0.05i', input="tmp.txt") fig.close()
import pygmt ex_name = 'pygmt_example_03' ps1 = ex_name + 'a.ps' fig = pygmt.GMT_Figure(verbosity=4, autopilot=False) report = fig.fitcircle('-L2', input="sat.xyg") #Stolen from command line until tifcircle works proj_option = '-C{}/{} -T{}/{} -S -Fpz -Q'.format(\ 330.169184777,18.4206532702,52.7451972868,21.2040074195) sat_pg = fig.project(proj_option, input="sat.xyg") ship_pg = fig.project(proj_option, input="ship.xyg") R = fig.gmtinfo('-I100/25', input=sat_pg) fig.psxy('-Rg -JX -O -Sp0.03i -> %s' % ps1, input=ship_pg) fig.psxy('-Rg -JX -O -Sp0.03i -> %s' % ps1, input=sat_pg)
import pygmt import numpy as np lons = np.linspace(-20, 50, 100) lats = np.linspace(20, 70, 100) X, Y = np.meshgrid(lons, lats) vx = np.sin(Y * np.pi / 180.0 * 5) vy = -np.cos(X * np.pi / 180.0 * 5) fig = pygmt.GMT_Figure("output.ps", figure_range='-20/50/20/70', projection='M9i', verbosity=1) fig.psbasemap('-B0 -P') fig.pscoast('-Bg30 -Dc -Glightbrown -Slightblue') gridx = fig.surface('-I3/3 -R-20/50/20/70', [X, Y, vx]) gridy = fig.surface('-I3/3 -R-20/50/20/70', [X, Y, vy]) fig.grdvector('-S.01i -Q0.1i+b+jc -Wthin', gridx, gridy) fig.close()
import pygmt import numpy as np #set up the figure class, tell it the output file, range option and projection fig = pygmt.GMT_Figure('example_07.ps', figure_range='-50/0/-10/20', projection='M9i', verbosity=0, autopilot=True) #lay down the coastlines fig.pscoast('-Slightblue -GP300/26:FtanBdarkbrown -Dl -Wthinnest -B10 --FORMAT_GEO_MAP=dddF') #plot a bunch of stuff fig.psxy('-Wthinner,-', 'fz.xy') fig.psxy('-Wthinnest -Gred -h1 -Sci -i0,1,2s0.01', 'quakes.xym') fig.psxy('-Wthin,blue', 'isochron.xy') fig.psxy('-Wthicker,orange', 'ridge.xy') #make the legend fig.psxy('-Gwhite -Wthick -A', [ np.array( [-14.5, -2. , -2., -14.5] ), \ np.array( [ 15.2, 15.2, 17.8, 17.8] ) ] ) fig.psxy('-Gwhite -Wthinner -A', [ np.array( [-14.35, -2.15 , -2.15, -14.35] ), \ np.array( [ 15.35, 15.35, 17.65, 17.65] ) ] ) fig.psxy('-Sc0.08i -Gred -Wthinner', [ np.array( [-13.5] ), np.array([16.5]) ] ) fig.pstext('-F+f18p,Times-Italic+jLM', ['-12.5 16.5 ISC Earthquakes',] ) #label the continents fig.pstext('-F+f30,Helvetica-Bold,white=thin', ['-43 -5 SOUTH' , \ '-43 -8 AMERICA' , \ '-7 11 AFRICA' ] ) #close the figure fig.close()
import pygmt fig = pygmt.GMT_Figure("output.ps", figure_range='g', projection='H7i', verbosity=4, autopilot=True) report = fig.fitcircle('-L2 -V4', input='sat.xyg') fig.pstext('-F+a30 -N -Gred', report) fig.fitcircle('-L2 -V4', input='sat.xyg', output='tmp.txt') fig.pstext('-F+a80 -N -Gblue', input='tmp.txt') fig.close()
import pygmt fig = pygmt.GMT_Figure("example_02.ps", figure_range='160/20/220/30r', projection='Oc190/25.5/292/69/4.5i', verbosity=0, autopilot=True, portrait=True) fig.gmtset('FONT_TITLE 30p MAP_ANNOT_OBLIQUE 0') g = fig.makecpt('-Crainbow -T-2/14/2') fig.grdimage('-E50 -B10 -X1.0i -Y1.25i', input='HI_geoid2.nc', cpt=g) fig.psscale('-D5.1i/1.35i/2.88i/0.4i -Ac -Bx2+lGEOID -By+lm -E', cpt=g) t = fig.grd2cpt('-Crelief -Z', 'HI_topo2.nc') gradient = fig.grdgradient('-A0 -Nt', input='HI_topo2.nc') fig.grdimage('-B+t\"H@#awaiian @#T@#opo and @#G@#eoid\" -B10 -E50 -Y4.5i --MAP_TITLE_OFFSET=0.5i',\ input = 'HI_topo2.nc', intensity=gradient, cpt=t) fig.psscale('-D5.1i/1.35i/2.88i/0.4i -I0.3 -Ac -Bx2+lTOPO -By+lkm', cpt=t) fig.close()
import pygmt fig = pygmt.GMT_Figure("output.ps", figure_range='g', projection='H7i') fig.pscoast('-Glightgray -A500') fig.psbasemap('-B30g30/15g15') fig.close()