Reputation: 675
I'm attempting to graph a complex function in a 3D space using GNUPlot's C++ library. I'm plotting a large array of 3D points.
Whenever I try to plot my function with the dgrid3d
option by sending the following plotting commands:
gp << "set dgrid3d 100,100\n";
gp << "splot" << gp.file1d(points) << "with pm3d title ' '" << endl;
(with points
being an array of my 3D function points)
I either get a blank graph or a very broken graph:
I tried changing up the grid precision values, but it always appears to mess up the graphing for some reason.
The best I'm able to get is to simply plot it with lines
:
I want to simply plot this as a solid surface, the color of which I want to map to another set of values.
What would be a better way of doing this? Is there another 3D graphing function that would be more suited to my needs?
Thanks for reading my post, any guidance is appreciated.
Upvotes: 0
Views: 143
Reputation: 15118
I am unable to reproduce any problem in plotting this file. The sequence:
set datafile separator comma
set palette defined (-1 "blue", 0 "white", 1 "red")
set dgrid3d 100,100
splot "data.text" with pm3d
produces the image above, which seems fine. You might want to consider using some variant of log-scaling if there is supposed to be information in the middles region of the sampling.
However I don't actually think gridding + pm3d is the best way to visualize this data. It seems clearer to me to simply use
set datafile separator comma
set xyplane at 0
splot "data.txt" with impulses
Second round answer
I think this figure will make clear what is happening. The surface fit to your original commands set dgrid3d 100,100
lies mostly in the range -2000 < z < -500. So when you clip it to a thin slice near z=0 there is nothing there to show except the spikes you saw from the beginning. So no error; that really is what the slice of your surface looks like.
I don't know what your data represents, nor what a different expected surface might be. So it's hard to suggest how to generate it.
Here is one more suggestion for what might be a useful presentation of the data. It clips the color assignments to [-40:40] but does not clip the z-values that generate the map.
set datafile sep comma
set palette defined (-1 "blue", 0 "white", 1 "red")
set dgrid3d 100,100
set cbrange [-40:40]
unset border; set ticscale 0,0
set xlabel "X"; set ylabel "Y" norotate; set cblabel "Z" norotate
set view map
splot "data.text" using 1:2:3 with pm3d
There are very few points near [0,0]. If you create a grid using a kernel function that spreads out the influence of each point over a large area, those few points with small |z| are dominated by the much larger number of points with very large |z|.
Here is an example of reducing the influence of each point to a local area with radius 2 and Gaussian fall-off of contribution. The corresponding command is set dgrid3d 100,100 gauss 2,2
. It emphasizes very local variation at the cost of overall smoothness of the surface. You will have to decide based on the nature of your data whether that is an appropriate representation.
By the way, there is one point in your data set with an anomalous entry:
1.000000,0.000000,-nan(ind)
The program is basically ignoring it. If it has some special significance you may want to edit that line to show either z=0 or z=, or place a dot on the surface to mark it or whatever else might be appropriate.
Upvotes: 1