Making a labeled contour plot
We got an introduction to contour plots in Chapter 8, The Third Dimension, where we saw that the contours can be drawn in a sequence of dash-dot styles; the contour values can then be identified by referring to the legend that gnuplot constructs for us automatically.
There is another style of contour plot that incorporates numerical labels directly on the contours. gnuplot does not support this style directly, but can be tricked into compliance, as shown in the following figure:
How to do it…
Type the following script:
unset key unset surf set view map set contour base unset clabel set xrange [0:5] set yrange [0:5] set style fill solid set for [n = 1:4] cntrparam levels discrete n**2 set for [n = 1:4] object n circle at n,n size 0.2 front fillcolor rgb '#ffffff' lw 0 set for [n = 1:4] label n sprintf("%d", n**2) at n,n center front splot x*y
How it works…
The first four lines set us up for making a typical contour plot (see Chapter 8, The Third Dimension). The command...