Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

partition the graph depending on some integer data column

Tags:

gnuplot

I have a data series with two columns, time and value, and an additional column with an integer number which says how the data was obtained. For example

0 15.1 0
1 20.2 0
2 34.3 1
3 41.5 2
4 61.7 1
5 79.6 0
6 48.2 0
7 92.1 1

Now, I usually plot the first two columns with

plot "data" u 1:2 w l

but I now desire to use the third column to "partition" the graph with vertical lines such that two contiguous records with the same value on third column get the same background. To each value in the third column, a single background color is associated.

In the case of the data above, the plot would have, for example, a blue background column starting from the time 0 to time 2 (exclusive), a green background column from 2 to 3, a red from 3 to 4, green again from 4 to 5, and so on.

Another solution (which I actually may prefer) is to have a vertical line in where the value of the third column switch its value, and each area of the graph has a label (say on the top axes) corresponding to the value of the third column.

Any idea? Thanks!

EDIT: follows an example of what I'd like to obtain. The value of the third column is placed on the top.

Partition plot with vertical lines

like image 881
AkiRoss Avatar asked Apr 24 '26 11:04

AkiRoss


1 Answers

top=100
set yrange [:top]

unset colorbox
set style fill solid 1.0
set palette defined (0 "blue",1 "green", 2 "red")

plot "data.dat" u ($1+.5):(top):3 w boxes lt palette,"" u 1:2 w l lc -1 lw 2

set palette defines colors corresponding to third column. .5 is shift, because histograms are centered around it's central value.

like image 193
Luuuucky Avatar answered Apr 30 '26 15:04

Luuuucky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!