|
From: sfeam (E. Merritt) <eam...@gm...> - 2013-03-01 04:51:38
|
On Thursday, 28 February 2013, Andreas wrote:
> Dear all,
>
> I'd like to plot a set of data points as impulses, colored according to the
> value in the 3rd column.
> Here is a short example:
>
> reset
> set xrange [0:5]
> set yrange [0:1]
> plot '-' u 1:2:3 w imp lc var
> 1 1 1 red
> 2 1 2 green
> 3 1 1 red
> 4 1 3 blue
> e
>
> What I get are four lines, two red ones at 1 and 3, a green one at 2 and a blue
> one at 4.
> So far so good.
>
> Now I'd like to get a key that shows each used color,
That part you can do by adding a dummy plot clause that will plot
nothing but will add the line samples and a blank title.
For this part no awk script is necessary.
plot '-' u 1:2:3 w imp lc var notitle, \
for [i=1:4] NaN lc i title " "
> labeled with the corresponding string value in column 4.
There is no way to do that inside gnuplot.
You can take key titles from a columnheader, but not from
within a line of data. It would make no sense, as a plot
can have only one title - not a new title for every line.
How about a parallel file that just contains the text labels
all on one line?
red green blue cyan yellow magenta
There are several ways you could read this into gnuplot
and use the separate column text as plot titles.
Ethan
> So far it shows just a single black line.
>
> I know, I could do something like
>
> plot 'data.file' u 1:($3=1 ? $2 : 1/0) t "red", '' u 1:($3=2 ? $2 : 1/0) t
> "green", '' u 1:($3=2 ? $2 : 1/0) t "blue"
>
> However, the actual data set is very large and generated on the fly using a awk
> script. And there are a total of 12 different instances in column 4. Using a
> solution like the one above would mean to run the awk script 12 times. Beside
> that don't like to compare column 3 to hard coded values (the number of
> instances might change in the future), this is not efficient enough, as the awk
> script takes quite some time to generate the data set.
>
> Any ideas on how to create the key from variable line colors directly?
> Preferably, using a single call to my awk script?
>
> Thank you,
> Andreas
|