gnuplothistogram

Gnuplot Histogram and Linecolor Loop


In reference to Gnuplot 6.0. What if the data file is structured not in one line (typical for histograms) but as 3x3 array:


1 0.12 172.7

2 0.11 183.8

3 0.75 55.4

Using loop:

gnuplot -p << EOF
set terminal png
set term pngcairo dashed
set title  "Title" font ",15"
set ylabel "y" font ",15"
set xlabel "x" font ",15"
set style fill solid 1.0
 
filename2(n) = sprintf("data%03.0f.dat", n)
outfile  (n) = sprintf("data%03.0f.png", n)

set boxwidth 1.0 
set style fill solid 1.0
set tics font ", 16"

do for [N=15:15] {
    set output outfile(N)
    infile = filename2(N)

    array scale[4]
    scale[1] = 'r/r_0:  80 - 100%' 
    scale[2] = '    50 - 80%'
    scale[3] = '    30 - 50%'
    scale[4] = '    10 - 30%'

plot for [i=1:3] filename2  (N) u(i): (column(3)):xtic(3) w boxes lc i  notitle,\
        for [i=1:3] keyentry w boxes lc i title scale[i]  at graph 0.22, graph (0.99-0.045*i)                
       }
EOF 

The problem is I need the u(i) loop to change histogram color 'boxes lc i' but it overplots the histogram leaving the same value at the end. Or I can use u (column(3)):xtic(3) but then I loose color:

same value or same color


Solution

  • Ok, let's try, maybe I got it now.

    If you absolutely want a legend with colored bars (which in your case would be redundant) you have to play some tricks:

    I hope the rest is self-explanatory. Check the following to the essence minimised script.

    Script:

    ### column as legend entry
    reset session
    
    $Data <<EOD
    1 0.12 172.7
    2 0.11 183.8
    3 0.75 55.4
    EOD
    
    set style fill solid 1.0
    set boxwidth 1.0 
    set yrange[0:]
    set key noautotitle
    
    plot $Data u 1:3:1:xtic(2) w boxes lc var, \
            '' u 1:3:3 w labels offset 0,0.7, \
         for [i=0:2] '' every ::i::i u 1:(t=strcol(2)):1 w boxes lc var ti t
    ### end of script
    

    Result:

    Actually, with redundant legend...

    enter image description here