Plotting curvilinear coordinate function on Cartesian plane

Suppose I have the following curvilinear coordinate (s, n) transform to Cartesian coordinates (x, y, z)

x = f(s, n) \\ y = g(s, n) \\ z = h(s, n)

where f(s, n), g(s, n), and h(s, n) are inaccessible functions (i.e. they can’t be expressed explicitly, I have them as an interpolation).

Is there a way to plot a heatmap or contour of h(s, n) in the space of \left(x, y\right)?

I’ve been studying curvilinear coordinates and Jacobians and doing

s = range(0, S, length = 101)
n = range(0, N, length = 101)
heatmap(f.(s, n'), g.(s, n'), h.(s, n'))

doesn’t throw an error, but doesn’t produce anything (i.e. it plots an empty axes) (as a wild attempt just to see if it would work, and I guessed it wouldn’t work but it was worth a shot (that said, I’m aware of curvilinear coordinates having potential regions of surjectivity in their transformation to Cartesian space, I just wanted to see what Julia would do)).

Extra note: When I went down the path of coordinate transforms theory, I could obtain the inverse transform Jacobian matrix (taking the interpolated functions f and g as differentiable), but that’s still a function of (s, n) so it doesn’t make sense to integrate it to obtain (s, n) as a function of (x, y) because… well… you can’t (AFAIK). So extra question, is there a way to handle the transform and obtain F(s, n) as a function of (x, y)?

I don’t know which plotting package you’re using, but usually, there is a function called mesh or similar that allows you to specify arbitrary values for x, y, and z, interpreting the last coordinate as either a color or a height. In e.g. PyPlot.jl, there is the function pcolormesh that does the former (see the examples at the bottom of the page).

1 Like

Hi,
correct me if I’m wrong, but you just want to plot z as a function of x and y ? This is what you can do with PyPlot.jl, example with polar coordinates:

using PyPlot
s = range(0,1,length=100)
phi = range(0,2pi,length=100)'
x = @. s*cos(phi) # =f(s,phi)
y = @. s*sin(phi) # =g(s,phi)
z = @. s^2*sin(2phi) # =h(s,phi)

contourf(x,y,z)
1 Like

Thanks @jagot and @fgerick! Yeah the things you suggested are exactly what I was looking for. The other backends didn’t have the functionality (AFAICT) to plot a contour/heatmap for arbitrarily defined input, as opposed to a grid.

1 Like

See example images in this GMT.jl issue

2 Likes