|
From: Allin C. <cot...@wf...> - 2026-03-23 17:02:14
|
I have a gnuplot routine that shows a correlation matrix as a heat
map. If the dimension of the matrix is not too great it prints the
value of the correlation coefficient in each "cell". Mostly this
works fine, but if the color of the cell is a relatively dark blue
(indicating a strong negative correlation) the default black text is
not very legible. So I'd like to make the textcolor conditional.
At present I have this plot statement:
plot $data matrix with image, $data matrix using \
1:2:(sprintf("%.1f",$3)) with labels
I'd like to append something like
tc $3 < -0.6 ? rgbcolor "white" : rgbcolor "black"
That doesn't work ("colorspec option not recognized", not very
surprisingly). But is there a way to do this?
Thanks for any guidance.
--
Allin Cottrell
Professor Emeritus
Wake Forest University
|
|
From: Juhász P. <pet...@gm...> - 2026-03-23 19:36:07
|
On Mon, 2026-03-23 at 11:57 -0400, Allin Cottrell via gnuplot-beta
wrote:
> I have a gnuplot routine that shows a correlation matrix as a heat
> map. If the dimension of the matrix is not too great it prints the
> value of the correlation coefficient in each "cell". Mostly this
> works fine, but if the color of the cell is a relatively dark blue
> (indicating a strong negative correlation) the default black text is
> not very legible. So I'd like to make the textcolor conditional.
>
> At present I have this plot statement:
>
> plot $data matrix with image, $data matrix using \
> 1:2:(sprintf("%.1f",$3)) with labels
>
> I'd like to append something like
>
> tc $3 < -0.6 ? rgbcolor "white" : rgbcolor "black"
>
> That doesn't work ("colorspec option not recognized", not very
> surprisingly). But is there a way to do this?
>
> Thanks for any guidance.
Hi,
AFAIK the labels style supports variable color. So you should be able
to do something like
$d << EOD
1 2 foo 0.3
2 3 bar 0.7
EOD
plot $d u 1:2:3:($4 > 0.6 ? 0xe00000 : 0x00e000) w labels tc rgb var
In this case you'd have to specify the colors as integers, which may be
slightly inconvenient and unmaintainable.
Other forms work too, like `tc variable` which would set the colors
based on the numbered color styles (same as used for functions/data by
the plot command), or `tc palette`, which draws colors according to a
color palette (either the default or the one you can set up before the
plot). This palette mode also draws a colorbar by default which you
have to disable if you don't want it.
So you have many options, neither of which is exactly what you want.
best regards,
Peter
|
|
From: Cottrell, A. <cot...@wf...> - 2026-03-23 21:02:35
|
On Mon, Mar 23, 2026 at 3:36 PM Juhász Péter <pet...@gm...> wrote:
>
> On Mon, 2026-03-23 at 11:57 -0400, Allin Cottrell via gnuplot-beta
> wrote:
> > I have a gnuplot routine that shows a correlation matrix as a heat
> > map. If the dimension of the matrix is not too great it prints the
> > value of the correlation coefficient in each "cell". Mostly this
> > works fine, but if the color of the cell is a relatively dark blue
> > (indicating a strong negative correlation) the default black text is
> > not very legible. So I'd like to make the textcolor conditional.
> >
> > At present I have this plot statement:
> >
> > plot $data matrix with image, $data matrix using \
> > 1:2:(sprintf("%.1f",$3)) with labels
> >
> > I'd like to append something like
> >
> > tc $3 < -0.6 ? rgbcolor "white" : rgbcolor "black"
> >
> > That doesn't work ("colorspec option not recognized", not very
> > surprisingly). But is there a way to do this?
> >
> > Thanks for any guidance.
>
> Hi,
>
> AFAIK the labels style supports variable color. So you should be able
> to do something like
>
> $d << EOD
> 1 2 foo 0.3
> 2 3 bar 0.7
> EOD
>
> plot $d u 1:2:3:($4 > 0.6 ? 0xe00000 : 0x00e000) w labels tc rgb var
>
> In this case you'd have to specify the colors as integers, which may be
> slightly inconvenient and unmaintainable.
Actually that suits me fine; I don't mind giving the colors as ints.
Thanks for the suggestion!
Allin Cottrell
|
|
From: Ethan A M. <me...@uw...> - 2026-03-23 21:39:40
|
Not exactly what you asked for, but one solution is to place the label in
an opaque box with neutral fillcolor:
set style textbox opaque fc "grey" noborder
plot $map1 matrix using 1:2:3 with image, \
$map1 matrix using 1:2:(sprintf("%g",$3)) with labels tc "black"
boxed
Here is a way to make it conditional on the matrix value using an extra
pass.
This requires gnuplot 6 for the "if" syntax
plot $map1 matrix using 1:2:3 with image, \
$map1 matrix using 1:2:(sprintf("%g",$3)) with labels tc "black" if
($3 > -0.6), \
$map1 matrix using 1:2:(sprintf("%g",$3)) with labels tc "white" if
($3 <= -0.6)
cheers,
Ethan
On Mon, Mar 23, 2026 at 10:02 AM Allin Cottrell via gnuplot-beta <
gnu...@li...> wrote:
> I have a gnuplot routine that shows a correlation matrix as a heat
> map. If the dimension of the matrix is not too great it prints the
> value of the correlation coefficient in each "cell". Mostly this
> works fine, but if the color of the cell is a relatively dark blue
> (indicating a strong negative correlation) the default black text is
> not very legible. So I'd like to make the textcolor conditional.
>
> At present I have this plot statement:
>
> plot $data matrix with image, $data matrix using \
> 1:2:(sprintf("%.1f",$3)) with labels
>
> I'd like to append something like
>
> tc $3 < -0.6 ? rgbcolor "white" : rgbcolor "black"
>
> That doesn't work ("colorspec option not recognized", not very
> surprisingly). But is there a way to do this?
>
> Thanks for any guidance.
>
> --
> Allin Cottrell
> Professor Emeritus
> Wake Forest University
--
Ethan A Merritt
Department of Biochemistry
University of Washington, Seattle
|
|
From: Cottrell, A. <cot...@wf...> - 2026-03-23 21:21:31
|
Thanks, Ethan. I'm glad to be alerted to the "trailing if" syntax in
gnuplot 6; I hadn't noticed that.
Allin
On Mon, Mar 23, 2026 at 4:41 PM Ethan A Merritt <me...@uw...> wrote:
>
> Not exactly what you asked for, but one solution is to place the label in an opaque box with neutral fillcolor:
>
> set style textbox opaque fc "grey" noborder
> plot $map1 matrix using 1:2:3 with image, \
> $map1 matrix using 1:2:(sprintf("%g",$3)) with labels tc "black" boxed
>
> Here is a way to make it conditional on the matrix value using an extra pass.
> This requires gnuplot 6 for the "if" syntax
>
> plot $map1 matrix using 1:2:3 with image, \
> $map1 matrix using 1:2:(sprintf("%g",$3)) with labels tc "black" if ($3 > -0.6), \
> $map1 matrix using 1:2:(sprintf("%g",$3)) with labels tc "white" if ($3 <= -0.6)
>
> cheers,
> Ethan
>
> On Mon, Mar 23, 2026 at 10:02 AM Allin Cottrell via gnuplot-beta <gnu...@li...> wrote:
>>
>> I have a gnuplot routine that shows a correlation matrix as a heat
>> map. If the dimension of the matrix is not too great it prints the
>> value of the correlation coefficient in each "cell". Mostly this
>> works fine, but if the color of the cell is a relatively dark blue
>> (indicating a strong negative correlation) the default black text is
>> not very legible. So I'd like to make the textcolor conditional.
>>
>> At present I have this plot statement:
>>
>> plot $data matrix with image, $data matrix using \
>> 1:2:(sprintf("%.1f",$3)) with labels
>>
>> I'd like to append something like
>>
>> tc $3 < -0.6 ? rgbcolor "white" : rgbcolor "black"
>>
>> That doesn't work ("colorspec option not recognized", not very
>> surprisingly). But is there a way to do this?
>>
>> Thanks for any guidance.
|