# Plot 3d data in a 2d contour plot

**URL:** https://discourse.julialang.org/t/plot-3d-data-in-a-2d-contour-plot/71251
**Category:** New to Julia
**Tags:** question, plotting, gmt
**Created:** [November 10, 2021, 10:23am UTC](https://discourse.julialang.org/t/plot-3d-data-in-a-2d-contour-plot/71251 "2021-11-10T10:23:04Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 10, 2021, 7:05pm UTC](https://discourse.julialang.org/t/plot-3d-data-in-a-2d-contour-plot/71251/2 "2021-11-10T19:05:09Z")

</div>

You can use GMT for this task but there are many more options in Julia.

The example below first grids the irregular points using the splines in tension method (_[Smith and Wessel, 1990](http://www.gps.alaska.edu/programming_2010/lectures/13_gmt2_smith_wessel_gridding.pdf)_). Once you have the grid, you can use your favorite plotting package to contour the data, including off course `GMT.jl`.

```julia
# 1 - INPUT DATA:
n = 200
xs, ys = 2π*(rand(n) .- 0.5), 2π*(rand(n) .- 0.5)
zs = 100*sin.(xs .* ys)

# 2 - GMT GRIDDING (Smith and Wessel [1990] Splines in tension):
using GMT
data = [xs ys zs]
x = y = LinRange(-π, π, 100)
G = GMT.surface(data, R=(extrema(x)..., extrema(y)...), inc=(step(x), step(y)), T=0.1)

```

 ![GMT_gridding_Spline_in_tension](https://global.discourse-cdn.com/julialang/original/3X/7/e/7e3d23d4716bd138078e66ee8e63543dcf51c1c7.jpeg)

---

_[View the full topic](https://discourse.julialang.org/t/plot-3d-data-in-a-2d-contour-plot/71251)._
