# Gnuplot.jl : Filled contour plot with constant color between contour lines

**URL:** <https://discourse.julialang.org/t/gnuplot-jl-filled-contour-plot-with-constant-color-between-contour-lines/63876>\
**Category:** Visualization\
**Tags:** question, gnuplot\
**Created:** [July 1, 2021, 6:58am UTC](https://discourse.julialang.org/t/gnuplot-jl-filled-contour-plot-with-constant-color-between-contour-lines/63876 "2021-07-01T06:58:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inna](https://avatars.discourse-cdn.com/v4/letter/i/8e8cbc/32.png) [@Inna](https://discourse.julialang.org/u/Inna)\
**Post date:** [July 1, 2021, 6:58am UTC](https://discourse.julialang.org/t/gnuplot-jl-filled-contour-plot-with-constant-color-between-contour-lines/63876/1 "2021-07-01T06:58:53Z")

</div>

Hello,  
using Gnuplot  
I want to plot contour lines with constant color between them.  
my code (from [https://lazarusa.github.io/gnuplot-examples/menu1/](https://lazarusa.github.io/gnuplot-examples/menu1/)) :

```julia
x = y = -15:0.33:15
fz(x,y) = sin.(sqrt.(x.^2 + y.^2))./sqrt.(x.^2+y.^2)
fxy = [fz(x,y) for x in x, y in y]
@gsp x y fxy "w l lc palette" "set view map"
@gsp :- "set contour base;set key off" "set auto fix"
@gsp :- "set cntrparam levels 15" "unset surface"
@gsp :- x y fxy "w labels"

```

As suggested here ([gnuplot - Filled contour plot with constant color between contour lines - Stack Overflow](https://stackoverflow.com/questions/20977368/filled-contour-plot-with-constant-color-between-contour-lines)), in order to get discrete color between lines i edit my code:

```julia
@gsp x y fxy " w pm3d" "set view map" "set pm3d interpolate 0,0"
@gsp :- "set contour base;set key off" "set auto fix"
@gsp :- "set cntrparam levels 6" "set surface"
@gsp :- x y fxy "w labels" "set palette maxcolors 6"

```

the output :

 ![x3](https://global.discourse-cdn.com/julialang/original/3X/3/b/3bc703391cfe8dee76c4d441e055facc926521d5.png)

I am not fine with this, because as you can see the lines do not fit very well with the colored sectors. If i do `interpolation 10,10`, the lines fit better but this slow my plot and it is heavy.

Finally, i am wondering if there is another way (easier / better) to get constant colors between lines?? (as there is in another packages)

Thank you!

---

<div class="post-metadata">

**Author:** ![maxfreu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxfreu/32/17468_2.png) [@maxfreu](https://discourse.julialang.org/u/maxfreu)\
**Post date:** [July 1, 2021, 1:26pm UTC](https://discourse.julialang.org/t/gnuplot-jl-filled-contour-plot-with-constant-color-between-contour-lines/63876/2 "2021-07-01T13:26:45Z")

</div>

Very psychedelic. Maybe set the step size of the x and y range a bit lower. Also you plot the data double which slows things down. Try this instead:

```julia
@gsp "set contour base; unset key; set auto fix"
@gsp :- "set cntrparam levels 6; set surface"
@gsp :- "set palette maxcolors 6; set size square"
@gsp :- x y fxy " w pm3d" "set view map" "set pm3d interpolate 5,5"

```

I think it will be a bit smoother, but the lines are still offset.

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [July 1, 2021, 4:07pm UTC](https://discourse.julialang.org/t/gnuplot-jl-filled-contour-plot-with-constant-color-between-contour-lines/63876/3 "2021-07-01T16:07:49Z")

</div>

don’t forget to trail at the end, as in

```julia
@gsp "set contour base; unset key; set auto fix" :-
@gsp :- "set cntrparam levels 6; set surface" :-
@gsp :- "set palette maxcolors 6; set size square" :-
@gsp :- x y fxy " w pm3d" "set view map" "set pm3d interpolate 5,5"

```

so that you just plot at the end the whole thing, this also makes things faster. Plus, probably the missing parts/colors/cornes is due to your original sampling of points, if I do

`x = y = -15:0.05:15`  
it looks smooth to me. Without any interpolation.

---

<div class="post-metadata">

**Author:** ![Inna](https://avatars.discourse-cdn.com/v4/letter/i/8e8cbc/32.png) [@Inna](https://discourse.julialang.org/u/Inna)\
**Post date:** [July 2, 2021, 8:41am UTC](https://discourse.julialang.org/t/gnuplot-jl-filled-contour-plot-with-constant-color-between-contour-lines/63876/4 "2021-07-02T08:41:45Z")

</div>

Hi, Thank you both of them !  
Finally this code:

```julia
using Gnuplot
x = y = -15:0.05:15
fz(x,y) = sin.(sqrt.(x.^2 + y.^2))./sqrt.(x.^2+y.^2)
fxy = [fz(x,y) for x in x, y in y]
@gsp "set contour base; unset key; set auto fix" :-
@gsp :- "set cntrparam levels 6; set surface" :-
@gsp :- "set palette maxcolors 6; set size square" :-
@gsp :- x y fxy " w pm3d" "set view map" 

```

(increasing my sample, without interpolation)) and the output is better:

 ![z4](https://global.discourse-cdn.com/julialang/original/3X/5/1/51c37715c8bdac07892bc064f43b90cd6464cdaa.png)
