Color gradient fill for figures

Dayum !

#!/bin/bash

gmt begin test png
    # generate a simple sinusoïd
	vecsta=$(gmt math -Q -1 PI MUL =)
	vecsto=$(gmt math -Q 1 PI MUL =)
	vecste=$(gmt math -Q 1 32 DIV =)
	gmt math -T$vecsta/$vecsto/$vecste T -C1 SIN = sin.txt

    # use @Esteban82's magic
	gmt grdmath -R-3.5/3.5/-1.5/1.5 -I0.01 Y = grd.nc
	gmt grdmath -R-3.2/3.2/-3.2/3.2 -I0.1 X Y ADD NORM = grd_out.nc
	gmt grdedit grd_out.nc -Er

    # define outside/inside colours
	gmt makecpt -Cgeo -T-3/3 -H > color_fg.cpt
	gmt makecpt -Cseafloor -I -T0/1 -H > color_bg.cpt

    # fill outside using inversed clip of function (forces a closed polygon similar to plot -L)
	gmt clip sin.txt -N 
		gmt grdimage grd_out.nc -Ccolor_bg.cpt -t25 
	gmt clip -C
    # fill inside using clip
	gmt clip sin.txt 
		gmt grdimage grd.nc -Ccolor_fg.cpt -t25
	gmt clip -C
    # redraw function for nicer result
	gmt plot sin.txt -Wthick,black 

gmt end show

This is kind of neat :grin:

1 Like