Search code examples
gnuplot

Gnuplot arrow line color using frac palette


I am trying to color arrows with the palette frac command as suggested in many sources, but it does not work for me.

Here is my MWE:

set terminal pdfcairo fontscale 1.0 size 19in,9in
set sample 1000

set output "plot_files/mapping_test.pdf"

set palette defined (0 '#0000cc' , 1 '#c00000') model RGB

row_num = 10

do for [i=1:row_num]{
    x_val = (i-1.0)/(row_num-1)
    #set arrow i from first x_val, graph 0 to first x_val, graph 1 nohead lw 2 lc 
    palette frac (i-1.0)/(row_num-1)
    set arrow i from first x_val, graph 0 to first x_val, graph 1 nohead lw 5 lc 
    palette frac 0.5 
}

plot sin(x)

Both do not work, giving a fraction, or computing it. I can change the color for example with lc rgb "red".

I am using version 5.2 level 4


Solution

  • You have discovered a bug. Thank you for the excellent report.

    Your script is correct, but the program doesn't notice the presence of palette-colored arrows when deciding whether or not to activate palette processing. It looks only at the plot itself. Well maybe it looks at a few other things also, but apparently not at arrows.

    Work around: everything exactly as you show but add an invisible plot component that uses the palette. The program will definitely notice this and thus turn on palette processing even though the plot component that would use it is not visible.

    # all setup as before
    # then
    plot sin(x), NaN with lines lc palette notitle
    

    If you do not want the sample palette on the right, add the command

    unset colorbox
    

    enter image description here