gnuplot - How to extract pm3d interpolated data? - gnuplot

I am trying to smooth some sparse data I have (format x,y,z) in a gnuplot graph. I need to plot using plot and the with image option because files generated with pm3d map are exceedingly oversized. What I like about pm3d map is that I can smooth my data with interpolate in such a way that the interpolated point only considers neighboring points (dgrid3d considers every point in the graph for the smoothing).
Hence what I want to do is set table and then export the pm3d map data with the interpolation set to whatever I desire, then use that data to do a plot ... with image. The problem is that when I do the following:
set table "out.dat"
set pm3d map interpolate 10,10
splot "in.dat"
gnuplot ignores the interpolate option and simply writes to "out.dat" the same info that was written in "in.dat".
Any ideas?
Alternatively, any stand alone code that interpolates 3D data in the same fashion of pm3d would also be useful.
Edit:
Apparently, I am using at work an "oldish" version of gnuplot: gnuplot 4.2 patchlevel 6, which only accepts the dgrid3d behavior as described above. At home, I am using a newer version (gnuplot 4.4 patchlevel 3) which comes with the option set dgrid3d {<rows>{,<cols>}} splines. This does more or less what I want.

Related

Trying to plot contours on Mac using the same script I use on windows on gnuplot

I have an issue with gnuplot on Mac. On windows everything seems fine I can easily draw contours on a "heat map". But on my Mac using the same script I can plot the map but not the contours on top of it.
https://imgur.com/a/x00bFnJ here is the two images. One with the contours is on Windows, other one is on Mac.
https://justpaste.it/6ws4h and here is the script.
I tried grid3d but they seem like not nearly accurate as the ones I have plotted on windows.
I cannot explain the difference between your two machines, but I think I can see where the problem arises. The following lines from your script are inconsistent with producing a plot with both a surface and contours shown:
set style data pm3d
set style function pm3d
set pm3d explicit at b
splot DATA with pm3d # command simplified
The issue is that both the default style and the explicit plot command specify pm3d, which is a filled-area surface plot. But contours need to be drawn with lines or with labels. You need some combination of defaults and explicit styles that allows you to mix both a surface and lines. I think either of these would do the trick:
set pm3d explicit
set style data lines
splot DATA with pm3d
or
set pm3d implicit
splot DATA with lines
Well! I will answer my own question.
set pm3d map
set contour surface
set cntrparam ...
sp "DATA" u 1:2:3 with pm3d lw 2,"" u 1:2:3 with lines nosurf
Solved my problem.!

Gnuplot: How to continue a pm3d plot to the outside of the set range?

I have a problem with plotting my data points with pm3d in gnuplot. In my data file, the points (2-dim domain) are not rectangular aligned, but parabolic as shown in this figure, where the data points are not aligned exactly above each other. My goal is to create a heatmap with pm3d for a specific xrange where the heatmap is continued to the borders of the selected xrange.
What I did:
Plotted the data set with pm3d using the following minimal code example:
set terminal qt
set xrange [-0.25:1.00]
set view map
splot "data.txt" u 1:2:3 with pm3d
What I got:
A heatmap of my data file, but with ugly corners at the border points at where I cut my x-domain, because the border points are not aligned "above" each other.
What I expected:
A heatmap where the "heat" values are continued to the real border of the domain as it is the case for a simple "with lines" plot, shown in this figure.
My attempts so far to achieve what I expected:
I tried several pm3d options, including the option clip1in, which only requires 1 clip of a "heat rectangle" to be inside the domain, but the result was that the corners are no laying outside of the domain, which doesn't solve the problem unfortunately.
Additional information:
OS: Ubuntu 20.04
$ gnuplot -V
gnuplot 5.2 patchlevel 8
If anybody knows how I achieve what I'm trying to do, it would be nice to share that knowledge!
Cheers!
Gnuplot 5.4 does offer this sort of smooth clipping on the z coordinate, but unfortunately that doesn't help because you want clipping on x in this case.
Here is an example of performing x clipping by manual intervention.
The complicated expression for the x coordinate is just to generate points
with a non-orthogonal grid.
xclip(x) = x > 6. ? 6. : x # clip x to maximum value of 6.
f(x,y) = sin(sqrt(x*x + y*y)) # some function to plot
set sample 21; set isosample 21
set view map
set xrange [-6 : 6]
unset key
set multiplot layout 1,2
set title "No clipping"
splot '++' using ($1+$2*$2/10.) :($2):(f($1,$2)) with pm3d
set title "Manual clipping at x=6"
splot '++' using (xclip($1+$2*$2/10.)):($2):(f($1,$2)) with pm3d
unset multiplot

Gnuplot and unstructured data is it possible

So far, I have been able to generate 2D contour plots using pm3d for a 2D structured data. However, I have got some data files that contains some flow visualisation of an unstructured grid that I am trying to plot next to the structured data. So far, I have found some links pointing to some scripts on how to generate contour plots Link, but it seems that the only way to do it is through dgrid3d, which only generates contours lines rather than the surface flow like this picture .
I am just wondering if there is a better way to generate similar plot using gnuplot tool.
Thank you very much for the help!
It is not correct that dgrid3d only produces lines. It is a preprocessing step for your data, which can subsequent be plotted using any style you want.
Here is an example using a pre-generated set of random points with Gaussian distribution. The code shown should work with gnuplot version 5.2 or newer. A slightly simpler plot command is possible in the current gnuplot version but the one shown still works also.
set view map
unset key
set cbtics format "" # no tic labels on the colorbar
set palette cubehelix negative
#
# Generate a grid from point density of previously-generated Gaussian
#
set dgrid3d 50,50 gauss kdensity
#
# Make all contour lines black
#
set contour base
set cntrparam levels incremental 0,200
set cntrparam firstlinetype 101
set for [L=101:110] linetype L linecolor "black" dashtype solid
set style textbox opaque noborder
set pm3d explicit at b
#
# Order of drawing is important.
# First the surface, then the lines, then the labels
#
splot $random using 1:2:(1) with pm3d, \
'' using 1:2:(1) with lines nosurface, \
'' using 1:2:(1):("") with labels boxed

Setting gnuplot yrange to fit one curve only

I have a Gnuplot script that draws 2 curves from a data file. If I don't specify yrange, Gnuplot sets it so that all the points of both curves fit in the figure. In my case I would like Gnuplot to only care about one of the curve (it does not matter if the other goes out of range, since I'm interested only in the parts of the figure where the second curve gets close to the first one).
I could find out the minimum and maximum values taken by the first curve, and manually set yrange to those values, but my Gnuplot script is intended to run automatically on many data files, producing many figures for which yrange is not the same, so I'm looking for a way to do that automatically.
Thanks
There are different options, depending on the used gnuplot version:
Version 5.0:
The data file which should be excluded from the autoscaling gets a noautoscale parameter:
plot 'first.dat' using 1:2, 'second.dat' using 1:2 noautoscale
Version >= 4.6:
Use the stats command to get the minimum and maximum value of the relavant data file:
stats 'first.dat' using 1:2
set yrange [STATS_min_y:STATS_max_y]
plot 'first.dat' using 1:2, 'second.dat' using 1:2
At least since 4.0:
Use set yrange [] writeback to save the autoscaled ranges from a plot command and set yrange restore to use them for a later plot:
set terminal push
set terminal unknown
set yrange [] writeback
plot 'first.dat' using 1:2
set yrange restore
set terminal pop
plot 'first.dat' using 1:2, 'second.dat' using 1:2

gnuplot ignores x and y ranges when using dgrid3d

I have a file with scattered data (points located approximatelly on the vertices of a regular grid): first two columns are the x and y coordinates, then a few more columns with other data that I need to plot. I want to obtain color maps that represent this data, and since points are scattered I'm using dgrid3d to generate a regular grid and have a smoother representation. My problem is that when I set dgrid3d, gnuplot ignores the x and y ranges and plot the grid outside the figure frame. Bellow is a minimal script to reproduce my problem:
set view map
set yrange [0.4:0.8]
set xrange [0.2:0.8]
set pm3d
set style data lines
set dgrid3d 100,100,4
splot "./Terr.dat" using 1:2:(log($6)) pal
The result that I obtain is the following image:
Setting the option clip1in or clip4in of pm3d has no effect. If I unset view so that the result is a 3D surface, it also ignores the x and y ranges. I could easily write an script to pre-process the data and remove the points outside the range I want, but gnuplot should be able to manage this. Any idea?
I'm using gnuplot 4.2 patchlevel 6
Thanks!
I'm not sure that I am able to reproduce your problem, but there are a few funny things with your script. I'm not exactly sure what the line set style data lines is supposed to do in this context as you're plotting with pm3d. I created a simple datafile:
0 1 4
1 0 5
0 0 2
1 1 3
And I plotted it using this script:
set view map
set yrange [0.4:0.8]
set xrange [0.2:0.8]
set dgrid3d 100,100,4
splot 'test.dat' u 1:2:3 w pm3d
And it seemed to "work" (I'm using gnuplot 4.6.0).
There are a few things of note however -- Notice that every point in my original domain was out of the given x and y ranges. Gnuplot still used those points when constructing the surface. This is also demonstrates reasonably nicely what the gnuplot weighting function looks like (although we could do even better by using only 1 point in our data file.)
UPDATE
Between my 2 computers, I have access to gnuplot4.2.6, gnuplot4.3.0, gnuplot4.4.2, gnuplot4.6.0, gnuplot4.6.1 and gnuplot4.7.0. gnuplot4.2.6 is the only version which exhibits the behavior you describe. It looks to me like they changed the behavior of pm3d in the 4.3 CVS branch, but didn't push those changes back into gnuplot4.2. The easy fix is to upgrade to gnuplot4.6 -- I've been using it as my default gnuplot for a few months now and it seems to be pretty stable.

Resources