# Plotting curvilinear coordinate function on Cartesian plane

**URL:** https://discourse.julialang.org/t/plotting-curvilinear-coordinate-function-on-cartesian-plane/47294
**Category:** General Usage
**Tags:** question, pyplot, gmt
**Created:** [September 25, 2020, 11:56pm UTC](https://discourse.julialang.org/t/plotting-curvilinear-coordinate-function-on-cartesian-plane/47294 "2020-09-25T23:56:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kapple](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kapple/32/218915_2.png) [@kapple](https://discourse.julialang.org/u/kapple)
#### Post date: [September 25, 2020, 11:56pm UTC](https://discourse.julialang.org/t/plotting-curvilinear-coordinate-function-on-cartesian-plane/47294/1 "2020-09-25T23:56:36Z")

</div>

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

```julia
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)?

---

<div class="post-metadata">

### Author: ![jagot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jagot/32/12217_2.png) [@jagot](https://discourse.julialang.org/u/jagot)
#### Post date: [September 26, 2020, 8:42am UTC](https://discourse.julialang.org/t/plotting-curvilinear-coordinate-function-on-cartesian-plane/47294/2 "2020-09-26T08:42:45Z")

</div>

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](https://github.com/JuliaPy/PyPlot.jl), there is the function [pcolormesh](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pcolormesh.html) that does the former (see the examples at the bottom of the page).

---

<div class="post-metadata">

### Author: ![fgerick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fgerick/32/13228_2.png) [@fgerick](https://discourse.julialang.org/u/fgerick)
#### Post date: [September 26, 2020, 9:06am UTC](https://discourse.julialang.org/t/plotting-curvilinear-coordinate-function-on-cartesian-plane/47294/3 "2020-09-26T09:06:28Z")

</div>

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:

```julia
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)

```

---

<div class="post-metadata">

### Author: ![kapple](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kapple/32/218915_2.png) [@kapple](https://discourse.julialang.org/u/kapple)
#### Post date: [September 30, 2020, 10:40pm UTC](https://discourse.julialang.org/t/plotting-curvilinear-coordinate-function-on-cartesian-plane/47294/4 "2020-09-30T22:40:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [September 30, 2020, 11:54pm UTC](https://discourse.julialang.org/t/plotting-curvilinear-coordinate-function-on-cartesian-plane/47294/5 "2020-09-30T23:54:08Z")

</div>

See example images in this GMT.jl [issue](https://github.com/GenericMappingTools/gmt/issues/3265)
