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

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

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), in order to get discrete color between lines i edit my code:

@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 :

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!

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:

@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.

1 Like

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

@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.

1 Like

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

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: