Andrew_E
Andrew_E

Reputation: 15

coloring multiple lines in gnuplot

I am trying to set line colors in gnuplot. I have a file with several datablocks in the usual format, separated by two empty lines. Is there a way I can set the color of each line in the plot to different colors. My graph looks like this right now

enter image description here

and my file like:

1 0.1 0.5
1 0.2 0.6
1 0.3 0.7
1 0.4 0.8

2 0.1 0.7
2 0.2 0.8
2 0.3 0.9
2 0.4 0.95

3 0.1 0.6
3 0.2 0.7
3 0.3 0.8
3 0.4 0.9

Upvotes: 1

Views: 1571

Answers (1)

maij
maij

Reputation: 4218

You can plot the lines block by block like this:

filename = "filename.dat"  # need the same file several times

stats filename             # get number of blocks
show variables             # check STATS_blocks

plot for [b=0:STATS_blocks-1] filename u 2:3 index b title ''.(b+1) w lp ps 1

See help stats which counts the blocks in your file, help for which loops over all available blocks, and help index which selects one specific block.

When I separate the data blocks in your example file by two lines as you have written, I get this result:

blocks colored differentl

If you want some control over the color, you might want to read help linecolor variable.

Upvotes: 4

Related Questions