FelixJN
FelixJN

Reputation: 570

Apply palette colors on set of functions

In gnuplot you can define and plot a set of functions quite simply:

set terminal pngcairo
set output 'test.png'
unset key
f(a,x) = a*x
plot for [a=0:100:2] f(a,x)

However I want to color the sets according to the value of a with a palette

set palette defined ( 0 'red' , 100 'green' )

The following does not work:

#random range from palette picked ( -> 0)
plot for [a=0:100:2] f(a,x) lc palette

#error no output
plot for [a=0:100:2] x:(f(a,x)):a lc palette

#colors not from palette
plot for [a=0:100:2] f(a,x) lc a

How to apply palette colors to a set of functions in gnuplot?

gnuplot Version 5.2 on linux

Upvotes: 1

Views: 256

Answers (1)

FelixJN
FelixJN

Reputation: 570

Picking colors from the palette by value is possible with lc palette cb <value>. Notably the range of the colorbox (cb) needs to be matched to the palette range:

set terminal pngcairo size 350,300
set output 'test.png'

f(a,x)=a*x

set palette defined ( 0 'red',  100 'green' )
set cbrange [0:100]

unset key
set xrange [0:10]

plot for [a=0:100:10] f(a,x) lc palette cb a lw 3

enter image description here

Upvotes: 1

Related Questions