How to fix a contour color of a 2D cut with gnuplot

137 Views Asked by At

Please I would like to have unique black lines for my 2D contour.


set terminal png size 800,800 font 'Times New Roman, 12'
set output 'TH1.png'
set view map
set pm3d map
unset surface
set cont base
set cntrparam levels 50
set isosamples 10
unset key 
set xrange[0:180]
set yrange[0:180]
set xlabel '{/Symbol q}'
set ylabel '{/Symbol q}''
set palette rgb 33,13,10
splot 'TH1TH2.dat' w ima, 'TH1TH2.dat' w l lt -4 lw 1.6

For values great than 2000 I want a red contour. Can someone help me? Here is my 2D cutenter image description here But I would like to have only the black lines. link for the data

2

There are 2 best solutions below

17
On BEST ANSWER

It would be ideal if we could use the original data (maybe minimized). Anyway, the following example creates its own data. If you need further explanations please let me know.

Script:

### contour lines with custom colors
reset session

set pm3d
set contour 
set cntrparam levels 20

### create some test data
set table $Data
    set isosamples 100
    set samples 100
    f(x,y)=(sin(1.3*x)*cos(.9*y)+cos(.8*x)*sin(1.9*y)+cos(y*.2*x))*4000/3.+2000
    splot [-5:5][-5:5] f(x,y)
unset table

set palette rgb 33,13,10
set size ratio 1
unset key
set tics out
set view map
set xrange[:] noextend
set yrange[:] noextend

myColor(v) = v>=2000 ? 0xff0000 : 0x000000

plot $Data index 0 u 1:2:3 w image, \
        '' index 1:999 u 1:2:(myColor($3)) w l lc rgb var
### end of script

Result:

enter image description here

Addition: (with OP's data, please reduce for a minimal example.)

I'm still confused. Ok, contour lines all in black, but values above 2000 in red? You could use the ternary operator to map all values >=2000 to the fixed value of 6000 (which will be red).

Script:

### contour lines with custom colors
reset session

FILE = 'TH1TH2.dat'

set pm3d
set contour
unset surface
set cntrparam levels 20

set table $Contour
    splot FILE u 1:2:3
unset table

set palette rgb 33,13,10
set size ratio 1
unset key
set tics out
set xrange[0:180]
set yrange[0:180]

myValue(v) = v>=2000 ? 6000 : v

plot FILE u 1:2:(myValue($3)) w image, \
     $Contour u 1:2 w l lc "black"
### end of script

Result:

enter image description here

Script 2:

### contour lines with custom colors
reset session

FILE = 'TH1TH2.dat'

set pm3d
set contour
unset surface
set cntrparam levels discrete -2000,-1800,-1600,-1400,-1200,-1000,-800,-600,-400-200,0,\
      200,400,600,800,1000,1200,1400,1600,1800,2000

set table $Contour
    splot FILE u 1:2:3 every 10
unset table

set palette rgb 33,13,10
set size ratio 1
unset key
set tics out
set xrange[0:180]
set yrange[0:180]

myValue(v) = v>=2000 ? 6000 : v

plot FILE u 1:2:(myValue($3)) w image, \
     $Contour u 1:2 w l lc "black"
### end of script

Result 2:

enter image description here

0
On

Your original figure attached to a previous question was a good figure. It showed the zero-level using a single black contour line, and showed regions of higher/lower values using palette coloring. In my judgment adding more lines in various colors is not an improvement; it adds clutter and confusion without conveying any new information. You would do better to stick with the original figure.

It would be possible, however, to add more emphasis to which areas are negative and which are positive. You could do this by defining a palette with a neutral color at 0 and two different color gradients indicating negative or positive values. For example:

set palette defined (-1 "orange-red", 0 "white", 1 "dark-blue")
test palette

enter image description here

Compared to the original palette, this makes it harder to judge precise values at any given point but makes it easier to focus on the positive or negative peaks.