Reputation: 125
I have a file with 16 data blocks separated by two blank lines so that I can plot each block by selecting its index. What I would like to do is to give a different color to each data block automatically so I tried:
plot "data.csv" using 2:1:-2 lc var
The problem is that there are not enough color for all the 16 data blocks i.e some data set have the same color while I would like to associate a unique color to each data block automatically? Is there a way to do this ?
Upvotes: 2
Views: 824
Reputation: 15093
The usual way is to take N slices from the color palette. You can define the color palette in many different ways, but so long as no color repeats in the palette this method will give you N distinct colors.
You ask specifically about 16 colors, so a minimal example using the default palette would be:
N = 16
plot for [i= 0 : N-1] "data.csv" index i using 2:1 lc palette frac (i * 1./N)
Upvotes: 2
Reputation: 751
There are many ways you could select the colours, automatically or not.
The linecolor
(or lc
) specifier can take
show colors
to see the full list of available colour
names),help colorspec
for more
details).I took the laziest approach I could think of, which is to select colours at random!
I provided to lc
a colorspec of the following form:
rgbcolor <integer val> # integer value representing AARRGGBB
In the script below, the <integer val>
are generated randomly,
in the range [000000, FFFFFF], where
FFFFFF (base 16) = 16**6-1 (base 10) = 16777215 (base 10).
This selects colours at random within the set of all possible colours
gnuplot supports, ignoring transparency (the AA in AARRGGBB).
unset key
set xrange [0:10]
seed = 4
x = rand(seed)
N = 16**6-1
plot for [i=1:16] x*i lc rgbcolor rand(0)*N
rand(0)
gives a number between 0 and 1 so rand(0)*N
gives a number between 0 and 16**6-1.
Since the seed is fixed (I picked 4), the sequence of random numbers and the set of colours is the same every time you run the script. You can try different seeds until all the line colours look different enough.
With the above script, I get this plot:
Upvotes: 2