Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot two datasets on the same graph with gnuplot. One with dgrid3d, the other one without

Tags:

gnuplot

I'm trying to plot two data sets with gnuplot. They are both (x, y, z) triplets. They are not arranged on a grid. I want to plot one of them using dgrid3d and pm3d. On top of that I want to overlay the other data set but as just scattered points.

To give a more concrete example: I am trying to plot the effect of a cylinder approaching a surface. I want to plot the response of the surface and that's where dgrid3d comes in handy. On top of that, I want to plot the position of the cylinder and I have its circumference as points.

I used:

set dgrid3d 100,100,4
set pm3d
splot "dataset1" with pm3d, "dataset2" with dots

The data set has about 100x100 points, arranged on a near-square, so 100,100 works best here. No matter how I plot the second data set, it always ends up being a square of the same dimensions as the cylinder, instead of a nice circle. When I turn dgrid3d off, I can plot the second data set on its own and the result is a nice circumference of the cylinder.

So my question is: is it possible to plot a 3D graph using two data sets, one using dgrid3d and the other one not using it?

like image 963
Wojtek Avatar asked Mar 13 '12 13:03

Wojtek


1 Answers

Yes, this is possible, but it is a little more tricky than you might think. The key is to use set table

For your example:

set dgrid3d 100,100,4
set pm3d explicit
set table "interpolated_data.dat"
splot "dataset1" with pm3d  #writes the interpolated data to "interpolated_data.dat"
unset table
unset dgrid3d
splot "interpolated_data.dat" with pm3d, "dataset2" with dots

The reason that your attempt didn't work is because when dgrid3d is in effect, All data read in is interpolated to a grid and then plotted using whatever style you specify.

From gnuplot's help dgrid3d When enabled, 3D data read from a file are always treated as a scattered data set.

As a side note, this method can also be used to plot contours on top of a pm3d as well.

like image 119
mgilson Avatar answered Nov 07 '22 20:11

mgilson