In cntrlabel contour plot
there is an excellent approach to the same problem when the 3D datafile corresponds to a rectangular grid.
Now, when the values are ungridded (that is, randomly scattered), gnuplot needs to grid them by interpolation, via the set dgrid3d nx,ny
command where nx and ny are the number of points along the x and y axes respectively.
I’ve done that then I’ve applied the solution proposed at cntrlabel contour plot
The best I’ve obtained, after having tried a number of variants, is this: if several lines happen to correspond to the same contour value, only one line is labeled (with -fortunately!- only one cntrlabel). The others are not labeled.
My (reduced) datafile “datos.txt” (previously sorted with zsort
) is as follows:
0 66 0.2
0 69 0.3
0 70 0.3
0 72 0.7
0 74 0.1
0 74.1 0.1
0 79 0.3
0 80 0.2
0 81 0.3
0.1 61 -0.1
0.1 70 0.3
0.1 74 0.7
0.1 75 0.8
0.1 75.1 0.3
0.1 78 0.2
0.2 73 0.4
0.2 75 0.5
0.3 59 0.5
0.3 74 0.4
0.3 75 0.1
0.3 76 0.6
0.3 78 0.2
0.4 71 0.3
0.4 73 0.4
0.4 74 0.6
0.5 54 1.1
0.5 69 0.2
0.5 76 0.6
0.5 84 0.3
0.6 55 0.3
0.6 67 0.3
0.6 68 0.4
0.6 76 0.4
0.6 77 0.5
0.6 79 0.2
0.6 80 0.4
0.7 68 0.2
0.7 72 0.1
0.7 73 0
0.7 76 0.4
0.7 76.1 0.4
0.7 77 0.5
0.7 77.1 0.3
0.7 81 0.2
0.8 46 1
0.8 54 0.1
0.8 63 0.5
0.8 68 0.3
0.8 73 -0.1
0.8 74 0.3
0.8 78 0.3
0.8 81 0.3
0.8 82 0.2
0.9 50 0.8
0.9 56 0.5
0.9 60 1.2
0.9 65 0.3
0.9 70 0.7
0.9 74 0.2
0.9 79 0
0.9 80 0.2
0.9 80.1 0.1
1 69 0.4
1 76 0.5
1 81 0.2
1.1 54 0.3
1.1 73 0.1
1.1 76 0.3
1.1 76.1 0.4
1.1 81 0.2
1.2 56 0
1.2 75 0.3
1.2 79 0.1
1.3 68 0.3
1.3 75 0.3
1.3 82 0.3
1.4 46 0.2
1.4 66 0.7
1.4 71 0.2
1.4 78 0
1.4 81 0.3
1.4 81.1 0.4
1.5 45 0.9
1.5 60 1.3
1.5 71 0.1
1.5 76 0.1
1.5 82 0.2
1.5 82.1 0.2
1.5 82.2 0.2
1.5 84 0.2
1.6 55 0.9
1.6 57 1.4
1.6 71 0
1.6 81 0.1
1.6 82 0.1
1.6 83 0.1
1.6 84 0.3
1.7 62 0.3
1.7 66 1
1.7 75 0.4
1.7 76 0.3
1.7 78 0.3
1.7 78.1 0.1
1.7 80 0.1
1.7 84 0.3
1.8 56 0.3
1.8 63 0.3
1.8 67 0.6
1.8 69 0.3
1.8 77 0.1
1.8 77.1 0.4
1.8 78 0.3
1.8 79 0.3
1.8 84 0.2
1.9 49 0.2
1.9 53 0.3
1.9 53.1 0.3
1.9 54 0.2
1.9 79 0.1
1.9 82 0.3
1.9 84 0.3
2 60 1
2 68 0.2
2 73 0.5
2 77 0.2
2.1 45 1
2.1 61 0.6
2.1 66 0.4
2.1 82 0.1
2.2 61 0.1
2.2 64 0.2
2.3 64 0.5
2.3 70 0.2
2.3 76 0.1
2.4 73 0.1
2.5 53 0.2
2.5 68 -0.1
2.5 74 0.1
2.5 79 0.1
2.6 43 0.9
2.6 65 0.8
2.6 70 0.1
2.8 61 0.4
2.9 61 0.5
3 54 0.4
3.1 69 0.2
3.2 57 0.3
3.2 67 0.4
3.5 65 1.1
3.8 54 0.3
3.8 60 0.2
3.9 53 0.6
3.9 65 0
4.1 46 0.9
4.1 48 0.8
4.2 56 0.8
4.3 43 1.1
4.3 45 1.1
4.6 44 1
4.7 44 0.7
4.7 46 0.9
4.7 52 0.7
5.5 44 0.9
6.6 70 -0.5
And my code is
reset session
set dgrid3d 900,900 qnorm 9 # I use large parameters because data are highly oscillatory
set table $Contour1
splot "datos.txt" u 1:2:3
unset table
set contour
set view 0,0,1
set cntrparam levels incremental -0.5,0.1,1.5
set palette rgbformulae 33,13,10
set cbrange[-0.5:1.5]
set colorbox vertical user origin 0.93,0.38 size .02,.585
set xrange [0:*]
unset surface
set table $ContourLabels
splot "datos.txt" u 1:2:3
# splot $Contour1 u 1:2:3 # THIS VARIANT YIELDS A CONTOUR PLOT WITH NUMERICAL ARTIFACTS (SEE THE 2ND PLOT BELOW)
unset table
set cntrlabel format "{/:Bold %.1f}" font "Times-New Roman, 12" # THIS HAS NO EFFECT (?)
plot $Contour1 u 1:2:3 w image notitle,
$ContourLabels u 1:2 w l notitle lc "black",
$ContourLabels u 1:2:3 every ::1:1:1:1 w labels notitle
The plot is as follows (except for labels and minor details):
And using the variant (see the script), it looks like this:
I guess the reason why it displays one cntrlabel for only one line among all lines with same cntrvalue, is that the every
command (see at the end of the script) deals only with blocks but not with sub-blocks. And I have many sub-blocks per block (as many as contours for the same value)
So does anyone know of any workaround to produce one cntrlabel for each contour ? Even better: one cntrlabel for every other contour ? (this, I guess with every
)