It was already possible to do this with GMT but it was a bit cumbersome, now with master version one can
f(x,y) = cos(2 * pi * x) * sin(2 * pi * y);
x = linspace(0,1,100);
G = mat2grid(f, x, x); # because countourf cannot yet ingest functions
# Clip inside a triangle for simplicity but the shape could be anything and any number of shapes
contourf(G, clip=[0.1 0.1; 0.5 0.9; 0.9 0.1], fmt=:png, show=true)