Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #3441 > unrolled thread

Varying colour of a line plot, using a palette

Started byJohn Edwards <johned0@gmail.com>
First post2016-11-10 11:03 +0000
Last post2016-11-11 10:23 +0000
Articles 6 — 3 participants

Back to article view | Back to comp.graphics.apps.gnuplot


Contents

  Varying colour of a line plot, using a palette John Edwards <johned0@gmail.com> - 2016-11-10 11:03 +0000
    Re: Varying colour of a line plot, using a palette Karl Ratzsch <mail.kfr@gmx.net> - 2016-11-10 13:37 +0100
      Re: Varying colour of a line plot, using a palette Ethan A Merritt <sfeam@users.sourceforge.net> - 2016-11-10 15:36 -0800
        Re: Varying colour of a line plot, using a palette John Edwards <johned0@gmail.com> - 2016-11-11 10:24 +0000
    Re: Varying colour of a line plot, using a palette Karl Ratzsch <mail.kfr@gmx.net> - 2016-11-10 18:32 +0100
      Re: Varying colour of a line plot, using a palette John Edwards <johned0@gmail.com> - 2016-11-11 10:23 +0000

#3441 — Varying colour of a line plot, using a palette

FromJohn Edwards <johned0@gmail.com>
Date2016-11-10 11:03 +0000
SubjectVarying colour of a line plot, using a palette
Message-ID<e8j2gjFpuv0U1@mid.individual.net>
Dear all,
I was wondering if anyone can think of a neat trick to vary the color of 
a line according to magnitude. E.g. If I plot sin(x) I'd like the color 
to vary with signal matnitude.

To explain further what I am trying to do, I'd like to use a palette of 
greens and reds so that when the signal goes over a threshold then the 
plot would vary (slowly) from green to red to highlight specific issues.

Thanks very much, as always,
John

[toc] | [next] | [standalone]


#3442

FromKarl Ratzsch <mail.kfr@gmx.net>
Date2016-11-10 13:37 +0100
Message-ID<o01pm4$q16$1@solani.org>
In reply to#3441
Am 10.11.2016 um 12:03 schrieb John Edwards:

> I was wondering if anyone can think of a neat trick to vary the color of 
> a line according to magnitude. E.g. If I plot sin(x) I'd like the color 
> to vary with signal matnitude.
> 
> To explain further what I am trying to do, I'd like to use a palette of 
> greens and reds so that when the signal goes over a threshold then the 
> plot would vary (slowly) from green to red to highlight specific issues.

Hm, very easy:

  set samp 800

  colourf(x) = (x<treshold) ? 0 : (x * 256) + (256 * (1-x) * 256)

  plot "+" us 1:(sin($1)):(colourf((sin($1)+1)/2)) w l lc rgb var lw 3

, where you define colourf(0<=x<1) so it returns a suitable 24 bit
integer, corresponding to the desired rgb colour.

[toc] | [prev] | [next] | [standalone]


#3444

FromEthan A Merritt <sfeam@users.sourceforge.net>
Date2016-11-10 15:36 -0800
Message-ID<o0309e$hrf$1@dont-email.me>
In reply to#3442
Karl Ratzsch wrote:

> Am 10.11.2016 um 12:03 schrieb John Edwards:
> 
>> I was wondering if anyone can think of a neat trick to vary the color of
>> a line according to magnitude. E.g. If I plot sin(x) I'd like the color
>> to vary with signal matnitude.
>> 
>> To explain further what I am trying to do, I'd like to use a palette of
>> greens and reds so that when the signal goes over a threshold then the
>> plot would vary (slowly) from green to red to highlight specific issues.
> 
> Hm, very easy:
> 
>   set samp 800
> 
>   colourf(x) = (x<treshold) ? 0 : (x * 256) + (256 * (1-x) * 256)
> 
>   plot "+" us 1:(sin($1)):(colourf((sin($1)+1)/2)) w l lc rgb var lw 3
> 
> , where you define colourf(0<=x<1) so it returns a suitable 24 bit
> integer, corresponding to the desired rgb colour.

Or you could use a defined palette:

set palette defined (0 "black", 0.5 "black", 0.75 "green", 1.0 "red")
f(x) = sin(x) * cos(x/10)
set xrange [-20:20]
set sample 800

plot '+' using ($1):(f($1)):(f($1)) with lines linecolor palette z

	Ethan

[toc] | [prev] | [next] | [standalone]


#3446

FromJohn Edwards <johned0@gmail.com>
Date2016-11-11 10:24 +0000
Message-ID<e8lkj4Fdu6eU2@mid.individual.net>
In reply to#3444
Thanks Ethan,

That is spot on.

All the best,
John

[toc] | [prev] | [next] | [standalone]


#3443

FromKarl Ratzsch <mail.kfr@gmx.net>
Date2016-11-10 18:32 +0100
Message-ID<o02avs$6hi$2@solani.org>
In reply to#3441
Am 10.11.2016 um 12:03 schrieb John Edwards:
> Dear all,
> I was wondering if anyone can think of a neat trick to vary the
> color of a line according to magnitude. E.g. If I plot sin(x) I'd
> like the color to vary with signal matnitude.
> 
> To explain further what I am trying to do, I'd like to use a palette
> of greens and reds so that when the signal goes over a threshold
> then the plot would vary (slowly) from green to red to highlight
> specific issues.

please answer in the newsgroup, not via email

[toc] | [prev] | [next] | [standalone]


#3445

FromJohn Edwards <johned0@gmail.com>
Date2016-11-11 10:23 +0000
Message-ID<e8lkghFdu6eU1@mid.individual.net>
In reply to#3443
On 10/11/2016 17:32, Karl Ratzsch wrote:
> Am 10.11.2016 um 12:03 schrieb John Edwards:
>> Dear all,
>> I was wondering if anyone can think of a neat trick to vary the
>> color of a line according to magnitude. E.g. If I plot sin(x) I'd
>> like the color to vary with signal matnitude.
>>
>> To explain further what I am trying to do, I'd like to use a palette
>> of greens and reds so that when the signal goes over a threshold
>> then the plot would vary (slowly) from green to red to highlight
>> specific issues.
>
> please answer in the newsgroup, not via email
>
Hi Karl,
Thanks very much, for the very quick and useful response.

Also apologies for the reply via email - user error on my part.

It has made me wonder if I can tweak your technique to implement a
"set palette rgb" type of function as used in splot etc.
All the best,
John

[toc] | [prev] | [standalone]


Back to top | Article view | comp.graphics.apps.gnuplot


csiph-web