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

colorize y-ranges

256 views
Skip to first unread message

Bart Vandewoestyne

unread,
Sep 10, 2008, 7:32:11 AM9/10/08
to
In a plot that shows Body Mass Index values over time, I would
like to give diffent colors to the different classifications,
e.g.

the area below 18.50 is 'Underweight' and should have a specific
color.

from 18.50 to 24.99 is 'Normal Range' also with its specific
color.

... and so on.

What is the most appropriate way to give different colors to
these y-ranges in my 2D plots?

Thanks,
Bart

--
"Share what you know. Learn what you don't."

Hermann Peifer

unread,
Sep 10, 2008, 9:07:17 AM9/10/08
to
On Sep 10, 1:32 pm, Bart Vandewoestyne

<MyFirstName.MyLastN...@telenet.be> wrote:
> In a plot that shows Body Mass Index values over time, I would
> like to give diffent colors to the different classifications,
> e.g.
>
> the area below 18.50 is 'Underweight' and should have a specific
> color.
>
> from 18.50 to 24.99 is 'Normal Range' also with its specific
> color.
>
> ... and so on.
>
> What is the most appropriate way to give different colors to
> these y-ranges in my 2D plots?
>

I would add coloured (nohead) arrows on top of the y-axis, similar to
arrows here: http://tinyurl.com/5da5xx

However, I do only have 2 weeks of gnuplotting experience, so there
might be smarter ways to get the effect.

Hermann

Ethan Merritt

unread,
Sep 10, 2008, 12:50:02 PM9/10/08
to
Bart Vandewoestyne wrote:

> In a plot that shows Body Mass Index values over time, I would
> like to give diffent colors to the different classifications,
> e.g.
>
> the area below 18.50 is 'Underweight' and should have a specific
> color.
>
> from 18.50 to 24.99 is 'Normal Range' also with its specific
> color.
>
> ... and so on.
>
> What is the most appropriate way to give different colors to
> these y-ranges in my 2D plots?

One option is to use the "splot" command and mode "set view map".
This gives you access to all the color-by-z-value options, and you
can simply replicate your y value as "z".

Hermann Peifer

unread,
Sep 10, 2008, 3:54:17 PM9/10/08
to

Thanks for this useful hint. I obviously misunderstood the OP's requirements.

Hermann

Hermann Peifer

unread,
Sep 11, 2008, 3:38:45 AM9/11/08
to
On Sep 10, 6:50 pm, Ethan Merritt <emerr...@eskimo.com.invalid> wrote:

> Bart Vandewoestyne wrote:
> > What is the most appropriate way to give different colors to
> > these y-ranges in my 2D plots?
>
> One option is to use the "splot" command and mode "set view map".
> This gives you access to all the color-by-z-value options, and you
> can simply replicate your y value as "z".

It is really a neat trick to color yranges of 2D plots via splot and
mode "set view map". This makes all my pre-processing and generation
of temp data files (according to value ranges) obsolete. I simply use:

splot 'testdata' using 1:3:(int($3/50)*50) notitle with points palette
ps 1 pt 5

And the result is what I wanted to have: http://tinyurl.com/563kt2

Thanks again, Hermann

Bart Vandewoestyne

unread,
Sep 11, 2008, 5:25:28 AM9/11/08
to
On 2008-09-10, Ethan Merritt <emer...@eskimo.com.invalid> wrote:
>
> One option is to use the "splot" command and mode "set view map".
> This gives you access to all the color-by-z-value options, and you
> can simply replicate your y value as "z".

Ethan,

I'm afraid I don't quite understand your suggestion. I'm
currently trying something like

set view map
splot 'weight_bart.txt' using 1:($2/(($4/100)**2)):(3) notitle w p pt 7

where I chose the (3) arbitrary so that I got rid of the error message. For
now, this gives me a 2D plot with my data points plotted in red, but how can
I now for example give the y-range from 20 to 25 a certain background-color?

It's a bit like drawing a rectangle in a certain color, with top and bottom
lines at 25 and 20, and left and right simply taken as the left and right edge
of the graph.

Hermann Peifer

unread,
Sep 11, 2008, 10:13:43 AM9/11/08
to
On Sep 11, 11:25 am, Bart Vandewoestyne
<MyFirstName.MyLastN...@telenet.be> wrote:

> On 2008-09-10, Ethan Merritt <emerr...@eskimo.com.invalid> wrote:
>
>
>
> > One option is to use the "splot" command and mode "set view map".
> > This gives you access to all the color-by-z-value options, and you
> > can simply replicate your y value as "z".
>
> Ethan,
>
> I'm afraid I don't quite understand your suggestion.  I'm
> currently trying something like
>
> set view map
> splot 'weight_bart.txt' using 1:($2/(($4/100)**2)):(3) notitle w p pt 7
>
> where I chose the (3) arbitrary so that I got rid of the error message.  For
> now, this gives me a 2D plot with my data points plotted in red, but how can
> I now for example give the y-range from 20 to 25 a certain background-color?
>
> It's a bit like drawing a rectangle in a certain color, with top and bottom
> lines at 25 and 20, and left and right simply taken as the left and right edge
> of the graph.
>

Below my 1st user-defined gnuplot function. So there is probably room
for improvement.
Here the result: http://tinyurl.com/5nzmn6


set title 'BMI test file'
set xdata time
set timefmt '%Y'
set format x '%Y '
set xtics rotate
set xrange ["2000":"2008"]
set yrange [5:45]
set ytics 10,5,40
set ylabel 'BMI'
set mytics 5
set grid xtics ytics mytics
set view map
set palette rgbformulae 33,13,10
set output 'bmi.png'
set cbrange [0:10]
set term png size 1200,900

# unset colorbox

# Initialise variable. Seems to be necessary.
x=1
# unset colorbox

# Initialise variable. Seems to be necessary.
x=1

# Calculate BMI
bmi(x) = $2/($4/100)**2

# Translate BMI values into suitable colours from palette
class(x) = bmi(x) < 15 || bmi(x) > 30 ? 10 : bmi(x) > 18.5 && bmi(x) <
25 ? 5 : 8

# Splot the points
splot 'data' using 1:(bmi(x)):(class(x)) notitle with points palette
ps 1 pt 5

Bart Vandewoestyne

unread,
Sep 11, 2008, 11:26:23 AM9/11/08
to
On 2008-09-11, Hermann Peifer <pei...@gmx.net> wrote:
>
> Below my 1st user-defined gnuplot function. So there is probably room
> for improvement.
> Here the result: http://tinyurl.com/5nzmn6

Hermann,

Actually, your example is not really what I want. You have a
color palette at the right side of the graph, but this is not the
way i want to do it.

I don't want a color palette next to my graph, I want the area *on*
the graph between for example 18 and 25 to be
colored green, and the underweight and overweight ranges red.
The colors of my dots with the actual BMI's from the data-file
all should have the same color, for example blue.

See what I mean? :-)

Anyway, thanks, but I'll keep on trying ;-)

Hermann Peifer

unread,
Sep 11, 2008, 1:25:23 PM9/11/08
to
Bart Vandewoestyne wrote:
> On 2008-09-11, Hermann Peifer <pei...@gmx.net> wrote:
>> Below my 1st user-defined gnuplot function. So there is probably room
>> for improvement.
>> Here the result: http://tinyurl.com/5nzmn6
>
> Hermann,
>
> Actually, your example is not really what I want. You have a
> color palette at the right side of the graph, but this is not the
> way i want to do it.

The color palette would be quickly gone with: unset colorbox

>
> I don't want a color palette next to my graph, I want the area *on*
> the graph between for example 18 and 25 to be
> colored green, and the underweight and overweight ranges red.
> The colors of my dots with the actual BMI's from the data-file
> all should have the same color, for example blue.
>
> See what I mean? :-)

Then you probably want something like the yellow boxes in the plot to which I pointed in my first posting. And my initial interpretation of your requirements wasn't completely wrong. I did the yellow boxes with set object rectangle, see http://gnuplot.sourceforge.net/docs/node226.html

Hermann

Bart Vandewoestyne

unread,
Sep 12, 2008, 3:45:48 AM9/12/08
to
On 2008-09-11, Hermann Peifer <pei...@gmx.eu> wrote:
>
> Then you probably want something like the yellow boxes in the plot to which
> I pointed in my first posting.

True.

> And my initial interpretation of your requirements wasn't completely wrong.
> I did the yellow boxes with set object rectangle, see
> http://gnuplot.sourceforge.net/docs/node226.html

I have been looking at that, but unfortunately I am working on a
Debian GNU/Linux stable box (etch), which comes with gnuplot
Version 4.0 patchlevel 0 and apparently this version does not
support 'set object'... so I was looking for alternatives that
*did* work in my version.

Regards,

Christoph Bersch

unread,
Sep 12, 2008, 4:12:25 AM9/12/08
to
Bart Vandewoestyne schrieb:

To follow Ethans suggestions, for gnuplot versions that don't support
rectangles you could try something like

set palette defined (0 "green", 0 "yellow", 0.999 "yellow", 1 "red")
set pm3d map
set cbrange[20:25]
set yrange[10:40]
set isosamples 7
splot y w pm3d, 'mydata.txt' u 1:2:(0) with points


The user-defined palette gives you the color jumps. The cbrange
specifies your 'yellow' regions, everything below the lower cbrange
limit is green, everthing above the upper cbrange limit is red. I you
adjust the yrange you may have to adjust the isosamples in order to get
the right coloring.

HTH
Christoph

0 new messages