colorsgnuplotpolar-coordinatesangulartics

How to change polar lines by different colors with respect to the interval with gnuplot


I'd like to change this polar plot by using Gnuplot as following:

  1. changing line color (radial lines and their semi circle edges) by different colors with respect to the range. For example, A to F interval as red, G to L as blue, and M to S keeping black

Below, I'm providing my code and I'd appreciate if someone give a hand with that.

enter image description here

`set decimalsign '.'

unset border
set polar
set angles degrees #set gnuplot on degrees instead of radians

set style line 10 lt rgb "black" lw 4.0 #redefine a new line style for the grid

set grid polar 20 #set the grid to be displayed every 20 degrees
set grid ls 10

set rrange [0:0.3]
set rtics 0, 0.05, 0.2 format "%.2f"

set size square 

set_label(x, text) = sprintf("set label '%s' at (0.22*cos(%f)), (0.22*sin(%f)) center", text, x, x) #this places a label on the outside

#here all labels are created
eval set_label(0, "A")
eval set_label(20, "B")
eval set_label(40, "C")
eval set_label(60, "D")
eval set_label(80, "E")
eval set_label(100, "F")
eval set_label(120, "G")
eval set_label(140, "H")
eval set_label(160, "I")
eval set_label(180, "J")
eval set_label(200, "K")
eval set_label(220, "L")
eval set_label(240, "M")
eval set_label(260, "N")
eval set_label(280, "O")
eval set_label(300, "P")
eval set_label(320, "Q")
eval set_label(340, "S")


set style line 11 lt rgb "blue" lw 10 pt 6 ps 6

plot "-" u 1:2 w lp ls 11
0    0.1499
020   0.1517
040   0.1474
060   0.1520
080   0.1526
100  0.1501
120  0.1491
140  0.1530
160  0.1515
180  0.1519
200  0.1534
220  0.1509
240  0.1501
260  0.1520
280  0.1481
300  0.1523
320  0.1529
340  0.1505
360    0.1499`

Solution

  • Here would be my suggestion. You can shorten the placing of the labels a bit. I am not aware that you can set individual colors for grid lines, so you have to color them "manually". Check the example below as a starting point. I assumed that after Q there is coming R not S.

    Code: (edit: colored border added)

    ### polar graph with colored grid lines
    reset session
    
    $Data <<EOD
    0    0.1499
    020   0.1517
    040   0.1474
    060   0.1520
    080   0.1526
    100  0.1501
    120  0.1491
    140  0.1530
    160  0.1515
    180  0.1519
    200  0.1534
    220  0.1509
    240  0.1501
    260  0.1520
    280  0.1481
    300  0.1523
    320  0.1529
    340  0.1505
    360    0.1499
    EOD
    
    set size square 
    unset border
    set polar
    set angles degrees
    unset label
    unset tics
    unset key 
    
    set style line 10 lt rgb "black" lw 1
    set style line 11 lt rgb "blue" lw 4 pt 6 ps 1
    
    set rrange [0:0.2]
    set rtics 0, 0.05, 0.2 format "%.2f"
    
    Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    N=18
    set grid polar 360./N ls 10
    set for [a=1:N] ttics (Alphabet[a:a] (a-1)*360./N)    # set ttic labels
    
    R=0.2
    myColors   = '0xff0000 0x00ffff 0x000000'
    myColor(n) = word(myColors,(n-1)/(N/3)+1)   #  !!! integer division
    
    set for [a= 1: N] object a circle at 0,0 size R arc [(a-1)*360./N:a*360./N] fc rgb myColor(a) lw 2 front wedge
    
    plot $Data u 1:2 w lp ls 11
    ### end of code
    

    Result:

    enter image description here