Re: conditional text color?

Ethan A Merritt <[email protected]> Mon, 23 Mar 2026 13:41:21 -0700
Newsgroups gmane.comp.graphics.gnuplot.devel
Message-ID <CALUAmEu4nwDaZUM3Jhoaf2+W3_vBno2Zuxc=0Qu3M3BKnOgmVg@mail.gmail.com>
--===============9206722581900465664==
Content-Type: multipart/alternative; boundary="0000000000006079f8064db70ffd"

--0000000000006079f8064db70ffd
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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 <=3D -0.6)

cheers,
         Ethan


On Mon, Mar 23, 2026 at 10:02=E2=80=AFAM Allin Cottrell via gnuplot-beta <
[email protected]> 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

--=20
Ethan A Merritt
Department of Biochemistry
University of Washington, Seattle

--0000000000006079f8064db70ffd
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">Not exactly what you asked for, but one s=
olution is to place the label in an opaque box with neutral fillcolor:<div>=
<br></div><div><span style=3D"font-family:monospace"><span style=3D"color:r=
gb(0,0,0)">=C2=A0 =C2=A0set style textbox opaque fc &quot;grey&quot; nobord=
er</span><br></span></div><div><span style=3D"font-family:monospace"><span =
style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0plot $map1 matrix using 1:2:3 with =
image, \</span><br></span></div><div><span style=3D"font-family:monospace">=
<span style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0</span></=
span><span style=3D"color:rgb(0,0,0);font-family:monospace">$map1 matrix us=
ing 1:2:(sprintf(&quot;%g&quot;,$3)</span><span style=3D"font-family:monosp=
ace">) with labels tc &quot;black&quot; boxed</span></div><div><span style=
=3D"font-family:arial,sans-serif"><br></span></div><div><span style=3D"font=
-family:arial,sans-serif">Here is a way to make it conditional on the matri=
x value using an extra pass.</span></div><div><span style=3D"font-family:ar=
ial,sans-serif">This requires gnuplot 6 for the &quot;if&quot; syntax</span=
></div><div><span style=3D"font-family:arial,sans-serif">=C2=A0</span></div=
><div>=C2=A0 =C2=A0<font face=3D"monospace">plot $map1 matrix using 1:2:3 w=
ith image, \</font><span style=3D"font-family:monospace"></span></div><div>=
<font face=3D"monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0$map1 matrix using 1:2:=
(sprintf(&quot;%g&quot;,$3)) with labels tc &quot;black&quot; if ($3 &gt; -=
0.6), \</font></div><div><font face=3D"monospace">=C2=A0 =C2=A0 =C2=A0 =C2=
=A0$map1 matrix using 1:2:(sprintf(&quot;%g&quot;,$3)) with labels tc &quot=
;white&quot; if ($3 &lt;=3D -0.6)=C2=A0</font></div></div><br><div class=3D=
"gmail_quote gmail_quote_container"><div class=3D"gmail_attr">cheers,</div>=
<div class=3D"gmail_attr">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Ethan</div><div=
 class=3D"gmail_attr"><br></div><div class=3D"gmail_attr"><br></div><div di=
r=3D"ltr" class=3D"gmail_attr">On Mon, Mar 23, 2026 at 10:02=E2=80=AFAM All=
in Cottrell via gnuplot-beta &lt;<a href=3D"mailto:[email protected]=
eforge.net">[email protected]</a>&gt; wrote:<br></div><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left=
:1px solid rgb(204,204,204);padding-left:1ex">I have a gnuplot routine that=
 shows a correlation matrix as a heat <br>
map. If the dimension of the matrix is not too great it prints the <br>
value of the correlation coefficient in each &quot;cell&quot;. Mostly this =
<br>
works fine, but if the color of the cell is a relatively dark blue <br>
(indicating a strong negative correlation) the default black text is <br>
not very legible. So I&#39;d like to make the textcolor conditional.<br>
<br>
At present I have this plot statement:<br>
<br>
plot $data matrix with image, $data matrix using \<br>
=C2=A0 1:2:(sprintf(&quot;%.1f&quot;,$3)) with labels<br>
<br>
I&#39;d like to append something like<br>
<br>
tc $3 &lt; -0.6 ? rgbcolor &quot;white&quot; : rgbcolor &quot;black&quot;<b=
r>
<br>
That doesn&#39;t work (&quot;colorspec option not recognized&quot;, not ver=
y <br>
surprisingly). But is there a way to do this?<br>
<br>
Thanks for any guidance.<br>
<br>
-- <br>
Allin Cottrell<br>
Professor Emeritus<br>
Wake Forest University</blockquote></div><span class=3D"gmail_signature_pre=
fix">-- </span><br><div dir=3D"ltr" class=3D"gmail_signature"><div dir=3D"l=
tr"><span style=3D"font-family:monospace"><span style=3D"color:rgb(0,0,0)">=
Ethan A Merritt
</span><br>Department of Biochemistry<br>University of Washington, Seattle<=
br>
<br></span></div></div></div>

--0000000000006079f8064db70ffd--


--===============9206722581900465664==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============9206722581900465664==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
gnuplot-beta mailing list
[email protected]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta

--===============9206722581900465664==--