Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

different colored legends for plot with labels

3,837 views
Skip to first unread message

Awhan Patnaik

unread,
Dec 25, 2010, 4:37:35 AM12/25/10
to
I have situations where I need to plot labels and need to distinguish
between them, so i plot them in different colors as follows:
plot 'data1' u 1:2:3 w labels tc rgb 'red' t 'red', 'data2' u 1:2:3 w
labels tc rgb 'blue' t 'blue'

however i can't appropriately modify the textcolor in the legends. i
was hoping something like the following will work

plot 'data1' u 1:2:3 w labels tc rgb 'red' t tc rgb 'red' 'red'

which obviously does not work :(

any advice to get this working?

Péter Juhász

unread,
Dec 25, 2010, 5:46:58 AM12/25/10
to

Unfortunately it's not possible to set different colors for different
key entries. You can set a global key text color that'll affect all
entries but that's it.

However, you can still get what you want with a set of manually
positioned labels:

unset key
set label 1 'red' at graph 0.8,0.8 tc rgb 'red'
set label 2 'blue' at graph 0.8,0.75 tc rgb 'blue'
plot 'data1' u 1:2:3 w labels tc rgb 'red', 'data2' u 1:2:3 w labels
tc rgb 'blue'

Péter Juhász

sfeam

unread,
Dec 25, 2010, 2:18:24 PM12/25/10
to
Awhan Patnaik wrote:

Yes.
The command "set key tc variable" will assign each key entry to be the
same color as the corresponding plot. Unfortunately for your particular
case, the color is taken from the line color rather than from the
text color. Nevertheless, you can force this by defining the text color
in terms of a line color:

set style line 1 lc rgb "red"
set style line 2 lc rgb "blue"
set style increment user # track line styles rather than line types
set key tc variable

plot 'data1' with labels tc ls 1, 'data2' with labels tc ls 2

In the development version of gnuplot (4.5) it is easier, because you can
reassign the colors of the linetypes themselves rather than defining
separate styles.

Péter Juhász

unread,
Dec 25, 2010, 3:32:29 PM12/25/10
to

> The command "set key tc variable"

I think this needs to be documented.

Péter Juhász

ps. Merry Christmas!

sfeam

unread,
Dec 26, 2010, 2:23:02 AM12/26/10
to
Péter Juhász wrote:

>
>> The command "set key tc variable"
>
> I think this needs to be documented.

It's in the first paragraph of "help key samples"

Ethan

Awhan Patnaik

unread,
Dec 26, 2010, 11:35:17 AM12/26/10
to
thanks so much guys :) the current solution does work for me though i
would very much like to be able to specify independently the text
color on the plot command itself rather than having it follow the line
style color. having said that i do know how much guys like me piss off
the developers by listing all their wishes instead of trying to
contribute missing features themselves. so much thanks for all the
good work.

Awhan Patnaik

unread,
Dec 26, 2010, 11:59:53 AM12/26/10
to
0 new messages