Ferdinando Randisi
Ferdinando Randisi

Reputation: 4378

Use linetype and color to distinguish many plots on the same graph in gnuplot 5

I am plotting something like 40 plots on the same figure in gnuplot 5. The standard palette quickly runs out of colors, so that it's impossible to distinguish which plot is which. An example (with 10 plots instead of 40, for clarity) is below enter image description here

If I could tell gnuplot to change dashtype as it runs out of colors, I would easily be able to tell the plots apart. How can I do that?

Nota Bene: the linetype behaviour changed in gnuplot 5. Commands that work in gnuplot 4 will probably fail in gnuplot 5.

Upvotes: 0

Views: 217

Answers (2)

theozh
theozh

Reputation: 25714

In gnuplot you have color, linewidth (lw), dashtype (dt), pointtype (pt), pointsize (ps) as differentiators. In your noisy and crowded plot, I would say pt, ps and lw are pretty much out of question.

Distinguishing 40 colors in a graph would be a challenge even for non-color-blind people. My guess is that you want a quick overview about these curves to "quickly" check how the curves behave (like finding some outliers or different shape or max or min values).

As you said: color and dashtype remain. In your answer you went for the standard 8 gnuplot colors and 5 dashtypes. You already noticed that some dashtypes are hard to differentiate, depending on the linewidth and graph size. Well, if you are using an ineractive terminal then you could always zoom in and differentiate the dashtypes (or maybe even pointtypes).

The example below uses 20 colors and 2 dashtypes via a defined palette. Two neigbouring curves have a different dashtype to have a clear differentiatior. The code can easily be changed, e.g. to 10 colors and 4 dashtypes.

Script:

### attempt to display 40 different distinguishable curves
reset session

N=40
# create some random test data
set print $Data
    do for [b=1:N] {
        y0 = rand(0)*300+100
        do for [r=1:200] {
            print sprintf("%d %.1f",r,y0=y0+rand(0)*10-5)
        }
        print ""
        print ""
    }
set print

set palette defined (0 "red", 1 "green", 2 "blue", 3 "magenta", 4 "yellow", 5 "cyan", 6 "black") maxcolors 20
set key out
set cbrange [0:40]
set cbtics 0,4,40
set mcbtics 4
# unset colorbox   #  uncomment this line if you want to remove colorbox

plot for [i=1:N] $Data u 1:2:(column(-2)) index i-1 w l lc palette lw 1.4 dt dt=((i+1)%2)*2+1 ti sprintf("%d",i) 
### end of script

Result:

enter image description here

Upvotes: 0

Ferdinando Randisi
Ferdinando Randisi

Reputation: 4378

A possible solution is to change the dashtype every eight plots. In a plot for command, this can be done like this:

plot for [i = 70:80] 'run'.i.'/e2e.txt' every 1 u 1:2 w l t ''.i dashtype i/8

enter image description here

this works, but the dashtype used are the 7 and 8 ones, which are quite similar to each other and hard to tell apart. Also this is a manual way of fixing it, and therefore error-prone and has to be re-engineered every time I plot something different. Ideally, I would like to change the default linestyle so that the change is performed automatically.

I'm posting the answer here to share a possible solution, in case someone needs it before a better one is provided.

Upvotes: 1

Related Questions