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

change line color when plot crosses Y value

995 views
Skip to first unread message

ginginsman

unread,
Jan 28, 2011, 9:41:28 AM1/28/11
to
I know I have seen this somewhere but cannot find it: I'd like to find
a way to change the color of a plot line when it crosses a specified
value of Y; blue above, red below, for example.

with data like this:

2011/02/01-03:31 0.59
2011/02/01-09:48 9.93
2011/02/01-16:11 -0.34
2011/02/01-22:24 8.88
2011/02/02-04:18 0.44
2011/02/02-10:32 9.96
2011/02/02-16:53 -0.36

set xdata time

set timefmt x  "%Y/%m/%d-%H:%M"

set samples 1000

plot 'data.txt' u 1:2 sm cspl

Find a way to change the curve color at any value > or < 1 (for
example).

OSX 10.6.6
GNUplot Version 4.4 patchlevel 2

Olaf Schultz

unread,
Jan 28, 2011, 10:53:15 AM1/28/11
to

maybe the hard way:

ycr=0.1
plot "data.txt u 1:($2>ycr?$2:1/0) lt 1 ,"" u 1:($2<=ycr?$2:1/0) lt 2 t ""

panchankos

unread,
Jan 29, 2011, 11:30:29 AM1/29/11
to
On Jan 28, 10:53 am, Olaf Schultz <o.ne...@enhydralutris.de> wrote:
> On Fri, 28 Jan 2011 06:41:28 -0800, ginginsman wrote:
> > I know I have seen this somewhere but cannot find it: I'd like to find a
> > way to change the color of a plot line when it crosses a specified value
> > of Y; blue above, red below, for example.
>
> > with data like this:
>
> > 2011/02/01-03:31   0.59
> > 2011/02/01-09:48   9.93
> > 2011/02/01-16:11   -0.34
> > 2011/02/01-22:24   8.88
> > 2011/02/02-04:18   0.44
> > 2011/02/02-10:32   9.96
> > 2011/02/02-16:53   -0.36
>
> > set xdata time
> >
>
> set timefmt x  "%Y/%m/%d-%H:%M">
> set samples 1000
> >
>
> plot 'data.txt' u 1:2 sm cspl

Can you use multiplot and position 2 plots so that 1 plot is above the
other:

For example:

Plot A: YRange [0:1]
PLot B: Yrange [1:10]

set origin 0,0
plot data with linecolor 1

set origin 0,1
plot data with linecolor 2

presumably data on plat A where y>1 would be clipped and data on plot
B where y<1 would be clipped.
You also want to turn off the xaxis and tic marks for plot B and make
sure the xrange for both plot is the same etc, etc.


ginginsman

unread,
Jan 29, 2011, 11:55:39 AM1/29/11
to

Well, the bit of progress I've made is the following, using code I
found (here, http://skuld.bmsc.washington.edu/~merritt/gnuplot/demo_svg/stringvar.html):
In multiplot: ("2" is just a test number for the condition), this
works nicely:

plot 'data.txt' u 1:2:($2>2) w filledcurves above lc rgb "blue"
plot 'data.txt' u 1:2:($2<2) w filledcurves below lc rgb "red"

but I've been unable to work out how to modify this to use the "sm
cspl" to draw lines rather than filled curves, which I do not want.

A. W. Dunstan

unread,
Feb 1, 2011, 9:55:04 AM2/1/11
to
ginginsman wrote:

Would something like this do the trick?

color(y) = y >= 0 ? (255*65535) : (255*255)
plot "data.in" using 1:2:(color($2)) with lines linecolor rgb variable

Tweak the definition of the "color()" function to give the desired colors.
The one above gives me yellow for y >= 0, green for y < 0.

(someone on this group showed me that a few years ago & it's been handy)


--
Al Dunstan, Software Engineer
OptiMetrics, Inc.
3115 Professional Drive
Ann Arbor, MI 48104-5131

"There are two ways of constructing a software design. One way is to make
it so simple that there are obviously no deficiencies. And the other way
is to make it so complicated that there are no obvious deficiencies."
- C. A. R. Hoare

ginginsman

unread,
Feb 3, 2011, 10:43:36 AM2/3/11
to

I'm unable to reproduce Al's results. It looks like a good solution.

Can anyone confirm for me that it works?
If so, perhaps dump for me the terminal settings and options you are
using?

A. W. Dunstan

unread,
Feb 3, 2011, 12:02:38 PM2/3/11
to
ginginsman wrote:

gnuplot> show terminal

terminal type is wxt 0

In ~/.gnuplot-wxt I've got:
raise=1
persist=0
ctrl=0
rendering=2
hinting=100

I've done output to JPG and PostScript files this way too (although it was a
few years ago). I'm using Gnuplot 4.2 patchlevel 3 on Fedora 10.

--
Al

ginginsman

unread,
Feb 3, 2011, 2:57:03 PM2/3/11
to

OSX + Aqua doesn't offer wxt, so I guess I'll try out some others.

Many thanks!

ginginsman

unread,
Feb 3, 2011, 3:14:53 PM2/3/11
to

Ooops, typo, OSX + gnuplot doesn't offer the wxt terminal. Apologies.

A. W. Dunstan

unread,
Feb 4, 2011, 10:00:32 AM2/4/11
to
ginginsman wrote:

It works with 'set terminal x11', too, if that's of any use to you.

--
Al Dunstan, Software Engineer
OptiMetrics, Inc.
3115 Professional Drive
Ann Arbor, MI 48104-5131

"There are two ways of constructing a software design. One way is to make

0 new messages