# Interpolated data contour plot like surface

**URL:** <https://discourse.julialang.org/t/interpolated-data-contour-plot-like-surface/15040>\
**Category:** Visualization\
**Tags:** gmt\
**Created:** [September 16, 2018, 11:39pm UTC](https://discourse.julialang.org/t/interpolated-data-contour-plot-like-surface/15040 "2018-09-16T23:39:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 16, 2018, 11:39pm UTC](https://discourse.julialang.org/t/interpolated-data-contour-plot-like-surface/15040/1 "2018-09-16T23:39:38Z")

</div>

Dear Plots experts—sorry, another question. if I have 3-D data (not function), I can use `surface` for a nice interpolated plot. alas, it’s not been adapted to a contour plot. and it clearly needs some smoothing aspects, like loess, over x-y-z (not just over x-y). still, it would be very nice. does anyone know if such a thing exists?

```julia
using Plots
n=100; xr= 10*rand(n); yr= 10*rand(n); zr= Float64[sin(xr[i])+cos(yr[i]) for i=1:n];
surface( xr, yr, zr ) ## does polygonal interpolation
contour( xr, yr, zr ) ## no such method

```

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 17, 2018, 5:50am UTC](https://discourse.julialang.org/t/interpolated-data-contour-plot-like-surface/15040/2 "2018-09-17T05:50:15Z")

</div>

that depends on the backend, I think - gr should interpolate contours. By the way, a better way to get support is to go to the Plots gitter channel, or the plots-bridged Slack channel - discourse is more intended for persistent discussion.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 17, 2018, 4:56pm UTC](https://discourse.julialang.org/t/interpolated-data-contour-plot-like-surface/15040/3 "2018-09-17T16:56:31Z")

</div>

thx, m. nope, gr is the default backend, and it cannot contour data, only functions.

PS: gitter is not topics-header organized. how can one keep track of conversations there?? it’s like a cacophony.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [September 17, 2018, 5:13pm UTC](https://discourse.julialang.org/t/interpolated-data-contour-plot-like-surface/15040/4 "2018-09-17T17:13:06Z")

</div>

It sounds like you need some kind of interpolation - maybe Interpolations.jl?

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 17, 2018, 11:29pm UTC](https://discourse.julialang.org/t/interpolated-data-contour-plot-like-surface/15040/5 "2018-09-17T23:29:31Z")

</div>

thx, dps.

looks too involved. the idea was to plot x,y,z data sets. Interpolations.jl seems to work happiest with regular grids. (only linear is supported without it.) With x and y not spaced equally, it’s not obvious enough to me how to work this well. plus, I think (but am not certain) that I have run into some bugs on Interpolations, either in the docs or in the package.

---

<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 17, 2018, 11:55pm UTC](https://discourse.julialang.org/t/interpolated-data-contour-plot-like-surface/15040/6 "2018-09-17T23:55:17Z")

</div>

You can do it with [GMT.jl](https://github.com/GenericMappingTools/GMT.jl). Unfortunately I forgot to port the `contour` module to the v0.5 version, but it’s now in master. With it you can do (contour the Matlab `peaks` function, also in GMT.jl)

```julia
x,y,z=GMT.peaks();
contour([x[:] y[:] z[:]], cont=1, annot=2, frame="a", fmt="png", show=1)

```

Without the master version you will have to use the _Monolithic_ method

```julia
gmt("pscontour -C1 -A2 -Ba -JX10c -W1p -R-3/3/-3/3 -P > cont.ps", [x[:] y[:] z[:]])
gmt("psconvert cont.ps -A -Tj -Fcont"); # Convert from PostScript to jpeg

```

 ![GMTjl_tmp](https://global.discourse-cdn.com/julialang/original/3X/f/0/f0ef0a80579060e3c5e78fcc2c0b98e25eb3308b.png)
