D2. Contours
Goal: the levels of the field: lines where it takes chosen values, over its colors.
gnuplot
# the field's levels: filled contours under contour lines, in the map view
set terminal svg size 600,420
set output 'pd02.svg'
set view map
set size ratio -1
set contour base
set cntrparam levels discrete -0.2, 0.2, 0.4, 0.6, 0.8
set palette viridis
set cblabel '{/Symbol f}'
set title 'levels -0.2, 0.2, 0.4, 0.6, 0.8'
unset key
set xlabel 'x'; set ylabel 'y'
splot 'field.dat' using 1:2:3 with pm3d notitle, \
'field.dat' using 1:2:3 with lines nosurface lc 'black' title 'levels'Why it works
- Contours are a 3D feature in gnuplot:
splotreads the field as a surface,set contour basecomputes its level lines, andset view maplooks at it from above, the 2D picture. with pm3dcolors the cells by the palette,with lines nosurfacedraws only the contour lines of the second item, each level in its own line type, as gnuplot.set cntrparam levels discrete ...lists the levels;levels incremental START, STEP, ENDandlevels N(about N levels at round values) are the other ways.
Try this
set cntrparam bspline: smoothed lines.splot ... with contourfill: bands between the levels instead of lines.set contour bothwithoutset view map: the lines on the surface and on the base, in 3D.
Pitfalls
- The contour lines of a coarse grid are polygons through the cells: refine the grid, not the smoothing, when the shape matters.
- A level at exactly a constant value of the field (0 far from the wave here) draws the noise of the round-off: choose levels away from it.
Reference: contours. Next: D3. A surface.