#
# Compare surface drawn "with pm3d" colored with a 7-color discrete palette
# to the same surface drawn "with contourfill" 
#

set colorbox user origin 0.75,0.2 size 0.15, 0.6
set cbtics scale .1
set view ,,,1.2
unset key

set xrange [-8:8]
set yrange [-8:8]

set rmargin at screen 0.75
set xyplane 0
set isosamples 51
set samples 51

set pm3d border lt -1 lw 0.5
set pm3d depth

sinc(x) = (x==0) ? 1.0 : sin(x) / x
f(x,y) = sinc( sqrt(x*x + y*y) )

set label 1 "set palette cubehelix\nmaxcolors 7"
set label 1 at screen 0.825, 0.9 center
set palette cubehelix maxcolors 7

set label 2 "splot with pm3d"
set label 2 at screen 0.4, 0.9 center

splot f(x,y) with pm3d

pause -1 "<cr> to continue"

set label 2 "set contourfill cbtics\nsplot with contourfill"
set contourfill cbtics

splot f(x,y) with contourfill

pause -1 "<cr> to set contourfill ztics"
reset

#
# Illustrate work in progress on new plot style "with contourfill"
# The style options are
#   set contourfill
#	auto N		N evenly spaced slices spanning zrange
#       ztics   	slice boundary at every z axis major tic
#	cbtics  	slice boundary at every cb axis major tic
#
# cbtics are still active even if the colorbox isn't shown,
# so an arbitrary set of slice boundaries can be constructe via
#   set cbtics ( z1, z2, z3, z4, ... )
#   unset colorbox
#   set contourfill cbtics
#
# In all cases the fill color is taken from the palette value for the
# midpoint z of the slice.  Other coloring methods are planned.
#

set key at screen 1, 0.9 right top
set samples 51
set isosamples 51
set contour surface
set xyplane 0
set zlabel "Z " 
set zlabel  offset character 1, 0, 0 font "" textcolor lt -1 norotate
unset xtics
unset ytics

set hidden3d back offset 0
set pm3d scansauto border lc "black" lw 0.5

set colorbox user origin 0.80,0.3 size 0.05, 0.5
set label 1 "set palette viridis"
set label 1 at screen 0.82, 0.9 center
set palette viridis
set cbtics 10 scale 5.

set label 2 "set contourfill ztics\nsplot with contourfill"
set label 2 at screen 0.4, 0.9 center
set cntrparam levels 5


g(x,y) = x**2 + y**2 * (1 - x)**3

set xrange [-1 : 5]
set yrange [-3 : 3]
set zrange [-10 : 10]
set view 60, 30, 0.8, 1.0
set lmargin screen 0
set bmargin screen 0

set contourfill ztics
splot g(x,y) with contourfill notitle

pause -1 "<cr> for 2D projection"

#
# cbtics must match cntrparam increments
# turn off "pm3d depth" to superimpose contour lines
#
set title "set view map;   splot with contourfill + contour lines"
unset label
set zrange [-25:25]
set cbrange [-21:21]
set cbtics -20, 5, 20
set contours
set cntrparam cubic
set cntrparam levels incremental -20, 5, 20
set cntrlabel onecolor
unset colorbox
unset hidden3d
set palette viridis positive
set contourfill cbtics
set pm3d scansauto border retrace
set view map
set tics scale 0
set key inside samplen .1 reverse
set key title "&{----} z = x^2 + y^2(1-x)^3"
splot g(x,y) with contourfill notitle, \
      g(x,y) nosurface lt black title "Contour levels Δz = 5"

pause -1 "<cr> to continue"
reset
