2

I have several files that I would like to plot in 2D without interpolation (i.e. a heat map). The data is in three columns (not as a matrix):

#Example data
0 0 1
0 1 -1
0 2 10

1 0 -2
1 1 -0.1
1 2 20

I am using the following commands (Version 4.4):

set pm3d map
set palette rgbformulae 22,13,-31
plot "file" us 1:2:($3>=0?0:$3) notitle w image

which produces the following image:

enter image description here

However, what I would like is:

  1. Ensure that all (column 3) values less than zero will follow the color palette
  2. Ensure that all (column 3) values greater than or equal to zero are white
  3. The color bar does not contain white

I want the image to look like this:

enter image description here

Note, that this is only an example. In my real data, the values that are greater than or equal to zero are dispersed throughout the data. I've been playing around with this all morning but have yet to come up with a solution. Any suggestions would be greatly appreciated.

slaw
  • 6,591
  • 16
  • 56
  • 109

1 Answers1

0

This is achieved by setting those values to NaN:

set view map
set palette rgbformulae 22,13,-31
plot "file" us 1:2:($3>=0?NaN:$3) notitle w image

This method works only with some terminals (see the discussion at Transparency for specific values in matrix using Gnuplot while preserving the palette?): It works at least with wxt, pdfcairo, pngcairo and png. It does not work with at least x11 and postscript.

The result with 4.6.3 is:

enter image description here

Community
  • 1
  • 1
Christoph
  • 47,569
  • 8
  • 87
  • 187
  • I tried that but GNUPLOT chokes with "GNUPLOT (plot_image): Visible pixel grid has a scan line longer than previous scan lines." I am using Version 4.4. Is there a solution for that version? – slaw Mar 06 '14 at 19:32
  • Which patchlevel? I just tested with 4.4.4 and it also worked fine, with 4.2.6 it doesn't. But there the colors of the NaN pixels are wrong, the command is ok. Note, that I used `set view map`, `pm3d` must *not* be used! – Christoph Mar 06 '14 at 19:37
  • Patch level 3. The NaN pixels end up being blue instead of white. – slaw Mar 06 '14 at 19:43
  • The "NEWS" for 4.4.4 compared to 4.4.3 contains the line "FIX NaN (not a number) implementation for Windows build". Maybe that is the relevant change. At the moment I don't know an other solution. – Christoph Mar 06 '14 at 19:45
  • I will wait a bit to see if anybody else has a solution. If not, I will definitely accept your answer! Thanks again. – slaw Mar 06 '14 at 19:47
  • I've tried this with 4.6.0 (on another machine with it installed) and the NaN pixels are still colored blue instead of white – slaw Mar 06 '14 at 21:07
  • Strange, there is even a demo which shows this in `demo/imageNaN.dem`. The result with 4.6.0 on Linux with the pngcairo terminal is http://i.stack.imgur.com/fXuhu.png (with the same result for 4.4.4). – Christoph Mar 06 '14 at 21:18
  • Is there some way to set them to white but not have white show up in the color bar? – slaw Mar 06 '14 at 21:27
  • Tweaking the palette like this: set pal defined (1 '#00008f', 8 '#0000ff', 24 '#00ffff', 40 '#ffff00', 56 '#ff0000', 63.9 '#800000', 64 '#FFFFFF') will add a white color at the max of the palette that is 'almost' invisible when the colorbox is drawn. Replace nan by the (exact) max value of the palette – bibi Mar 07 '14 at 06:34
  • I just tried this on 4.6.5 with the same result (blue pixels instead of white). I will trying tweaking the palette as described – slaw Mar 07 '14 at 20:12
  • It's quite hard to say whats happening: Which OS do you have, Windows? Do you run exactly the script which I posted? – Christoph Mar 08 '14 at 16:33