2
votes

I'm using Gnuplot to generate a histogram but I need to color some of them in another color if the value are over/under a specific value. Eg if value < 10, color the specific histogram green. If value > 10, value < 20, color the specific histogram yellow. If value > 20, color histogram red.

So I want the graph to be like this:

x . y . color

1 . 4 . green

2 . 15 . yellow

3 . 40 . red

The values (x and y) comes from a database so I won't be able to tell Gnuplot which x-values I want to colorize as the values will change from time to time.

Am I able to accomplish this with Gnuplot (And php)?

Thanks!

2

2 Answers

6
votes

You can use the following gnuplot script:

set style fill transparent solid 0.5 noborder
set boxwidth 0.95 relative
set palette model RGB defined (0 "green", 1 "yellow", 2 "red")
plot 'path\to\your\file' using 1:2:($2<=10 ? 0 : $2<=20 ? 1 : 2) with boxes palette

The contents of my test file are

1 4
2 15
3 40

and the outcome I get is

enter image description here

2
votes

Given this datafile:

1 4  green
2 15 yellow
3 40 red

The following line works:

plot for [color in "green red yellow"] 'test.dat' using 1:(strcol(3) eq color ? $2:NaN):(0.95) with boxes lc rgb color