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


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

Plot emtpy labels from file entries using 'matrix with image'

Started byneurino <lelli.luca@googlemail.com>
First post2014-11-20 17:15 +0100
Last post2014-11-22 15:26 +0100
Articles 4 — 2 participants

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


Contents

  Plot emtpy labels from file entries using 'matrix with image' neurino <lelli.luca@googlemail.com> - 2014-11-20 17:15 +0100
    Re: Plot emtpy labels from file entries using 'matrix with image' Ethan A Merritt <EAMerritt@gmail.com> - 2014-11-20 21:39 -0800
      Re: Plot emtpy labels from file entries using 'matrix with image' neurino <lelli.luca@googlemail.com> - 2014-11-21 13:19 +0100
        Re: Plot emtpy labels from file entries using 'matrix with image' neurino <lelli.luca@googlemail.com> - 2014-11-22 15:26 +0100

#2638 — Plot emtpy labels from file entries using 'matrix with image'

Fromneurino <lelli.luca@googlemail.com>
Date2014-11-20 17:15 +0100
SubjectPlot emtpy labels from file entries using 'matrix with image'
Message-ID<m4l428$pv1$1@virtdiesel.mng.cu.mi.it>
Hello group,

I have a file with a 4x4 score matrix and I'd like to plot the upper 
triangular with one color palette and the lower triangular with a 
different one, overlaying the score value (MWE code at the bottom).

The original file looks like this

0.00 0.65 0.65 0.25
0.25 0.00 0.75 0.25
0.50 0.60 0.00 0.25
0.75 0.25 0.10 0.00

First, I created two separate files and used multiplot to have 2 
different palettes.

FILE1 (upper triangular)
0.00 0.65 0.65 0.25
nan  0.00 0.75 0.25
nan nan 0.00 0.25
nan nan nan 0.00

FILE2 (lower triangular)
0.00 nan nan nan
0.25 0.00 nan nan
0.50 0.60 0.00 nan
0.75 0.25 0.10 0.00

Second, I plot the score values with
using 1:2:( sprintf('%.2f', $3 ) )

However, the 'nan' isn't interpreted as blank/empty and skipped but 
written onto the plot.

Any idea how to skip the nans and make gnuplot plot empty labels from 
individual entries of the data files?

The ternary operator in the following fashion do not seem to do the job
using 1:2:( \$3 == '' ? 1/0 : sprintf('%.2f', (\$3) ) )

Thanks.

---
set multiplot
set autoscale fix
unset key

set datafile missing "nan"
set cbrange [0:1]
unset colorbox

set palette defined (0 "white", 0.1 "#9ecae1", 1.0 "#3182bd")

plot FILE1 matrix with image, \
	FILE1 matrix using 1:2:( sprintf('%.2f', $3) ) with labels font ',16'

set palette defined (0 "white", 0.1 "#a1d99b", 1.0 "#31a354")

plot FILE2 matrix with image, \
	FILE2 matrix using 1:2:( sprintf('%.2f', $3) ) with labels font ',16'

unset multiplot

[toc] | [next] | [standalone]


#2639

FromEthan A Merritt <EAMerritt@gmail.com>
Date2014-11-20 21:39 -0800
Message-ID<m4mj5d$o71$1@dont-email.me>
In reply to#2638
Let's try the simple answer first.  You used the command 

> The ternary operator in the following fashion do not seem to do the job
> using 1:2:( \$3 == '' ? 1/0 : sprintf('%.2f', (\$3) ) )

but you probably did not realize that a curious property of NaN is that
is by definition never equal to any other entity, including itself.
So   A=NaN;   if (A != A) print "A is not a number"

So your test would better be written

  using 1:2:(($3!=$3) ? "" : sprintf('%.2f', $3))

Of course there may be other problems as well, but try that first.

By the way, it is very rare to have to use multiplot to create a
single plot.  I don't think you really need to do so here either.
But leave that for now.
	
	Ethan



neurino wrote:

> Hello group,
> 
> I have a file with a 4x4 score matrix and I'd like to plot the upper
> triangular with one color palette and the lower triangular with a
> different one, overlaying the score value (MWE code at the bottom).
> 
> The original file looks like this
> 
> 0.00 0.65 0.65 0.25
> 0.25 0.00 0.75 0.25
> 0.50 0.60 0.00 0.25
> 0.75 0.25 0.10 0.00
> 
> First, I created two separate files and used multiplot to have 2
> different palettes.
> 
> FILE1 (upper triangular)
> 0.00 0.65 0.65 0.25
> nan  0.00 0.75 0.25
> nan nan 0.00 0.25
> nan nan nan 0.00
> 
> FILE2 (lower triangular)
> 0.00 nan nan nan
> 0.25 0.00 nan nan
> 0.50 0.60 0.00 nan
> 0.75 0.25 0.10 0.00
> 
> Second, I plot the score values with
> using 1:2:( sprintf('%.2f', $3 ) )
> 
> However, the 'nan' isn't interpreted as blank/empty and skipped but
> written onto the plot.
> 
> Any idea how to skip the nans and make gnuplot plot empty labels from
> individual entries of the data files?
> 
> The ternary operator in the following fashion do not seem to do the
> job using 1:2:( \$3 == '' ? 1/0 : sprintf('%.2f', (\$3) ) )
> 
> Thanks.
> 
> ---
> set multiplot
> set autoscale fix
> unset key
> 
> set datafile missing "nan"
> set cbrange [0:1]
> unset colorbox
> 
> set palette defined (0 "white", 0.1 "#9ecae1", 1.0 "#3182bd")
> 
> plot FILE1 matrix with image, \
> FILE1 matrix using 1:2:( sprintf('%.2f', $3) ) with labels font ',16'
> 
> set palette defined (0 "white", 0.1 "#a1d99b", 1.0 "#31a354")
> 
> plot FILE2 matrix with image, \
> FILE2 matrix using 1:2:( sprintf('%.2f', $3) ) with labels font ',16'
> 
> unset multiplot

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


#2640

Fromneurino <lelli.luca@googlemail.com>
Date2014-11-21 13:19 +0100
Message-ID<m4nakp$aq2$1@virtdiesel.mng.cu.mi.it>
In reply to#2639
On 2014-11-21 05:39:04 +0000, Ethan A Merritt said:

>> The ternary operator in the following fashion do not seem to do the job
>> using 1:2:( \$3 == '' ? 1/0 : sprintf('%.2f', (\$3) ) )
> 
> but you probably did not realize that a curious property of NaN is that
> is by definition never equal to any other entity, including itself.
> So   A=NaN;   if (A != A) print "A is not a number"

Incredible ... never thought at this property.

> So your test would better be written
>   using 1:2:(($3!=$3) ? "" : sprintf('%.2f', $3))
> Of course there may be other problems as well, but try that first.

Which is the solution. It worked. Here the result
http://www.iup.uni-bremen.de/~luca/downloads/gnuplot/cci.png


> By the way, it is very rare to have to use multiplot to create a
> single plot.  I don't think you really need to do so here either.
> But leave that for now.

Likely, slicing the matrix with proper indexing would pick up 
triangular submatrices, however I couldn't come up myself with such a 
smart solution. It came natural to think at the layered structure of a 
postscript file, hence the 'multiplot' approach. If you have 
alternative suggestions, I'm very happy to explore them.

Many thanks.

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


#2641

Fromneurino <lelli.luca@googlemail.com>
Date2014-11-22 15:26 +0100
Message-ID<m4q6eu$dr1$1@virtdiesel.mng.cu.mi.it>
In reply to#2640
On 2014-11-21 12:19:37 +0000, neurino said:

>> By the way, it is very rare to have to use multiplot to create a
>> single plot.  I don't think you really need to do so here either.
>> But leave that for now.
> 
> Likely, slicing the matrix with proper indexing would pick up 
> triangular submatrices, however I couldn't come up myself with such a 
> smart solution. It came natural to think at the layered structure of a 
> postscript file, hence the 'multiplot' approach.

I thnik this can be solved as follows (credit Cristoph-Stackoverflow):

1 - define a single palette, which contains as negative values one 
palette and as positive values the other palette

# here -1.0 corresponds to dark blue and 1.0 to dark green
set palette defined (-1.0 "#31a354", -0.1 "#a1d99b", 0 "white", 0.1 
"#9ecae1", 1.0 "#3182bd")

2 - Based on the x- and  y-value from the single file, you can 
distinguish if the color value should be taken from the negative or 
from the positive palette part.

Column $1 is the running x-value
Column $2 is the running y-value
Column $3 is the z-value (i.e. the actual score value)

So, with the following line
plot ifile matrix using 1:2:( \$1 < \$2 ? -\$3 : \$3) with image,

I'm checking when the x values is less than the y value (lower 
triangular, i.e. below the diagonal), then assign a negative z-value, 
which picks the color in the negative part of the palette and the file 
doesn't need to be split manually anymore.

Cheers.

[toc] | [prev] | [standalone]


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


csiph-web