Plot two datasets on the same graph with gnuplot. One with dgrid3d, the other one without - 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?

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.

Related

Gnuplot: Alternatives for pm3d

I am exporting the 3D plot data from Mathematica and trying to plot it in gnuplot. I would like to put color gradient like we do in pm3d. But the constraint of pm3d is that we need a space each time when there is a sign change. Since I have a large collection of points and the format of the Mathematica output is different, is there any alternatives to pm3d?

Gnuplot-Circular 2D Heatmap

I have to plot the temperature map of a cross-section inside a cylinder for which I use this data. When I plot the data as a heat map in Gnuplot all I get is the following figure. My heat map is supposed to be a quarter-circle. The coordinates in my data file correspond only to a quarter circle. But Gnuplot gives me a square. How do I get a quarter-circle heat map?
MWE
set pm3d map interpolate 0,0
set dgrid3d
splot 'Temp.dat' using 1:2:3
dgrid3d can only make a rectangular grid, but that is not the main problem: The default algorithm of "dgrid3d" severely distorts your data. Use "splines" (or "qnorm" ?).
You have to do this in two steps:
set dgrid3d splines
set table $dat
splot dataf
unset table
unset dgrid3d
The interpolated grid is saved in the datablock $dat. You can now plot it with pm3d, and disable any point which is outside of your original dataset.
set pm3d map ....
splot $dat using 1:2:(($1**2+$2**2) > 16) ? 1/0 : $3)
(This needs gnuplot > 5.0. If you still have an older version, you have to use a temporary file instead of $dat.)

GNUPLOT contour over splot with pm3d from different data files

i am struggling in trying to splot a nonuniform binary matrix from a datafile1, and plot over it a contour of another variable, over the same grid but another datafile. Both the datafiles are in binary matrix shape.
# CONTOUR SETTINGS
set contour surface
set cntrparam level discrete 0.3,0.067
# PRINT CONTOUR ON TABLE
set table 'tablefile_contour'
splot 'contour_variable_field_binary' binary with l lt -1
unset table
# FIELD SPLOT
set view map;
splot 'field_to_be_plotted_2D_binary' binary with pm3d,\
'tablefile_contour' u 1:2:3 w p lt -1
basically i have been trying to follow some recipes fished along the internet.
If I try to plot only the splot, i obtain a 2D pic. I want to put on it isolines from the 'contour_variable_field_binary' file, so i splot it on a table file and i splot it together with the field to be plotted. I do it, i obtain a black pic.
How can i superimpose isolines from another file? Any clues?
Since my suggestion is a bit too long for a comment:
Have you tried plotting both original files together? You can disable contouring of the first file using nocontour, and disable the surface for the second plot with nosurface:
set contour base
set cntrparam level discrete 0.3,0.067
set pm3d map
splot 'field_to_be_plotted_2D_binary' binary with pm3d nocontour,\
'contour_variable_field_binary' binary with l lt nosurface
Can't tell if this works properly because I have not data for testing.

Change color of dgrid3d surface in Gnuplot

Is there a way to change the color of the lines of the surface when using dgrid3d? It seem simple enough but everything I've looked at only speaks of coloring the whole surface using pm3d. I have multiple surfaces on one plot and would like to be able to specify the color of each. For example, one would be red, another would be blue, another would be black, another would be green.
If you have your data available in a file Data.dat then give this a try:
set dgrid3d 10,10
set style data lines
set pm3d
splot "Data.dat" pal
The dgrid3d tells gnuplot how many entries there are in the x- and
y-direction (those are the two comma separated parameters)
The style data lines lets gnuplot plot the result with lines
instead of points
The pm3d fills the surface with a color (if you leave this away you
will just see the lines)
pal makes the lines appear in the color of the specified value
There are much more options you can set, but i find those the most relevant.
Seems like.
set dgrid3d
splot "file.dat" with lines linecolor 4
Where 4 is color you need.
For multiple surfaces you can try
set dgrid3d splines
set table "surface1.dat"
splot "file1.dat"
unset table
unset dgrid3d
for every surface you need.
And after all surface description
splot "surface1.dat" with lines linecolor 4, splot "surface2.dat" with lines linecolor 7 ...

How to properly handle 3D data and create heatmaps in gnuplot 4.6?

I have temperature data from eight different nonequidistant depths over several days and I would like to plot it as heatmap. As far as I know I have two options. I can use "with image" but that assumes equidistant points so that makes just 8 pixel thin strip or I can use pm3d which need proper grid(I am not sure what proper grid is). I found that dgrid3d can make the grid for me but that erases any dependency on depth for some reason. Can someone please explain this behavior to me?
Here is the code and the data I use.
https://docs.google.com/file/d/0B2TfUgjtGRVReV9ocFVvM1BKd2M
set timefmt "%Y-%m-%d %H:%M:%S"
set xdata time
set view map
set dgrid3d
splot './Data/MO-03t_.txt' every ::2 u 1:3:4 with pm3d
the dgrid3d does not plot your data. Instead, something like two-dimensional splines are calculated from your data. Then, gnuplot creates a (by default) 10x10 matrix, and fills it with values interpolated from the splines. This matrix is then plotted.
But I have an other solution for you:
set timefmt "%Y-%m-%d %H:%M:%S"
set xdata time
# for the nice colors
set pm3d
# For debugging: place ticmarks only vor values with data
set ytics (0.02, 0.04, 0.06, 0.11, 0.31, 0.41, 0.61, 0.91)
plot './Data/MO-03t_.txt' every ::2 u 1:3:(1800):($3<0.2?.005:0.05):4 w boxxyerrorbars fs solid lc palette
The boxxerrorbars ... lc palette takes using <x>:<y>:<deltaX><deltaX>:<z>
The delta values are half the width of the boxes, i.e. it means plot a box from x-deltaX;y-deltaY to x+deltaX;y+deltaY for each datapoint.
Here, the width of the boxes is 3600 seconds, the height is either 0.1 or 0.01, depending on the y-value.
Here is the result:
However, you can still improve the height of the boxes.
And instead of 4+1 columns, you can also pass 6+1 columns with
using <x>:<y>:<xlow>:<ylow>:<xhigh>:<yhigh>:<z>
Here, the borders of the boxes are given as absolute values, not as distance from the x-y-value.

Resources