3-Dimensional Plot in GnuPlot where color is a fourth column in my data file?
Asked Answered
C

1

9

I have a datafile that looks like this:

1   2   3   0.5
2   8   9   0.2
3   4   78  0.4
6   5   7   0.01
9   9   9   0.3
10  12  18  0.9
6   8   4   1

I would like to do a graph like this http://2.bp.blogspot.com/-378_rAaSSVU/UzU0gnGcr9I/AAAAAAAABnU/P1GwP9RKBkM/s1600/gnuplot.png Where the 4th column is the color.

I tried - obviously incorrect because I do not use the fourth column but I failed to find anything in the documentation:

set dgrid3d 30,30
set view 60,45
set hidden3d
dataFile='prova.dat'
set palette defined (0 "blue", 0.5 "white", 1 "pink")
set pm3d 
splot dataFile u 1:2:3 with pm3d

Is somethings like that possible?

Caramel answered 29/8, 2014 at 17:18 Comment(0)
A
8

Using only pm3d you can use a fourth column to select a color independent of the z-value. Together with dgrid3d this is not directly possible, because the gridding is not performed on the color column.

You can use a workaround: First you plot the gridded z-value to one file, then the gridded color values to a second file and as last point you disable dgrid3d, merge the two temporary files on-the-fly and plot their values:

set dgrid3d 30,30
dataFile='prova.dat'

set table dataFile.'.grid'
splot dataFile u 1:2:3
unset table

set table dataFile.'.color'
splot dataFile u 1:2:4
unset table

set view 60,45
set hidden3d
set palette defined (0 "blue", 0.5 "white", 1 "pink")
set autoscale cbfix
set pm3d
unset dgrid3d
set ticslevel 0
splot sprintf('< paste %s.grid %s.color', dataFile, dataFile) u 1:2:3:7 with pm3d notitle

enter image description here

Note, that paste is a command line tool for Unix-like operation systems. For a similar solution for windows, you can e.g. write a small Python script paste.py (see my answer to Get ratio from 2 files in gnuplot for a possible implementation). Then you must run the wgnuplot_pipes.exe binary file and the splot command becomes

splot sprintf('< python paste.py %s.grid %s.color', dataFile, dataFile) u 1:2:3:7 with pm3d notitle

Of course, for this you must have python installed and the python binary must be available via the PATH environment variable.

Ameliaamelie answered 29/8, 2014 at 17:37 Comment(9)
Thank You for the swift answer. I'm not a skilled user hence I do not understand -running the code with version 4.6 patchlevel 5- the warnings generated by the code: line 19: warning: Skipping unreadable file "paste prova.dat.grid prova.dat.color" line 19: warning: No usable data in this plot to auto-scale axis range splot sprintf('paste %s.grid %s.color', dataFile, dataFile) u 1:2:3:7 with pm3d notitle ^ "C:\Users\Baroni\Desktop\prova.plt", line 19: All points x value undefined I installed python and PATH, I created a script as yours linked but no progressCaramel
You must use the last command I wrote, with the < python paste.py ...). The < is essential, and you must use the full name of your python script (propabaly paste.py).Ameliaamelie
I used past&copy so I suppose the problem is the absence of Gnuplot.py in my env, I'm trying to solve this problem.Caramel
No, you don't need Gnuplot.py! And according to your error message you didn't use copy & paste of the correct line. You must use the splot command I mentioned after the image: splot sprintf('< python paste.py %s.grid %s.color', dataFile, dataFile) u 1:2:3:7 with pm3d notitle.Ameliaamelie
Using Python with its PATH & Gnuplot, ther're this warnings: <code> line 19: warning: Skipping unreadable file "< python paste.py prova.dat.grid prova.dat.color" "C:\Users\Baroni\Desktop\prova.plt", line 19: warning: No usable data in this plot to auto-scale axis range gnuplot> splot sprintf('< python paste.py %s.grid %s.color', dataFile, dataFile) u 1:2:3:7 with pm3d notitle ^ "C:\Users\Baroni\Desktop\prova.plt", line 19: All points x value undefined </code>Caramel
Do you use wgnuplot_pipes.exe?Ameliaamelie
I'm sorry for the extended discussion (I've not enough reputation to instantiate a chat). I try to open -through Win Interface- the script py with Open with... wgnuplot_pipes.exe" but a window appears and disappears quickly and I'm not able to see anything.Caramel
If you want to see the result interactively, you should start wgnuplot_pipes.exe and then from the interactive gnuplot terminal run load "script.gp", where the file script.gp contains all your plotting commands.Ameliaamelie
I do get an output from this code, but when I add gauss filtering to dgrid3d, the plot disappears.. any clue how to fix this?Wycoff

© 2022 - 2024 — McMap. All rights reserved.