Gnuplot and unstructured data is it possible - gnuplot

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

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 - Trying to create a waterfall/ fence plot

I try to create a nice waterfall map with gnuplot showing the development of an optical spectrum with current. My goal is to achieve something close to this :
A waterfall plot
I have tried this command
splot [][1160:1200][-80:-30] "Waterfall.txt" u 1:2:3 w l lw 3 lc rgb 'black'
The "Waterfall.txt" file has the format suggested in the accepted answer here Gnuplot: fence plot from data.
I have ignored z-data values lower than -80, substituting them with NaN.
The outcome is shown in the next image link.
My attempt
As you can see, compared with the previous figure, this is confusing to the reader. How can I fix it in order for it to be close to the first image and thus more clear to the viewer ?
Edit:
Thanks to #Ethan's answer it worked. The outcome is shown in the figure below. The only problem is the transparency of each fence, that reveals partially the subsequent fences.
The new attempt
Assume twenty 2D files each containing Y and Z:
Gnuplot version 5.2
filename(i) = 'silver.dat'
set pm3d scansauto
set style fill solid noborder
set xyplane at 0
set log z
unset key
splot for [k=20:1:-1] filename(k) using 1:(k):2:(1.0):2 with zerrorfill \
fc "white" lc "black" lw 2
I don't have your data files so I use the same file 20 times for the purpose of illustration. It is based on the zerror demo in the gnuplot distribution and online demo set.
Note that the base of each 'fence' is set to (z=1.0) rather than zero because of the log scale on z.
The figure shown was made using a newer gnuplot. It uses partial transparency and a fancier bounding box that isn't in 5.2

How to apply beatiful fading edge occlusion on Gnuplot's splot function?

Hello fellow stackers,
So I am a gnuplot afficcionado and I keep trying to use gnuplot to draw all sorts of things (including molecules) using it. These days I decided that it would be awesome if I could draw polyhedran in it with this beautiful thining-edge occlusion effect that we see in the interactive javascript polyhedral images here. See how the backside of the polyhedron is drawn differently from the front side and how they change dynamically as you rotate the solid? How can I do that in gnuplot?
I agree that is a really nice representation. Gnuplot cannot currently do the equivalent of "draw the inside edges using thinner lines", but the combination of partial transparency and using the background color as the fill color for the faces creates almost the same effect.
# Generation of polyhedral vertices and faces not shown.
# Each face is an object of type polygon, e.g.
# set object 1 polygon from ... to ... to ...
# make all the faces semi-transparent
set for [i=1:20] object i fillstyle transparent solid 0.6 fillcolor bgnd border lw 2
# use pm3d depthorder sorting to render the objects
# NB: gnuplot version 5.3 required
set for [i=1:20] object i polygon depthorder
set xrange [-2:2]; set yrange [-2:2]; set zrange [-2:2]
set view equal xyz
set view 30,30,1.5
unset border
unset tics
unset key
unset label
splot NaN
Results shown below for a cube and for an icosahedron. You can rotate them interactively as with any other splot.

Smoothing out contourplot in Gnuplot?

I am trying to plot a simple contour plot (in gnuplot) for the Himmelblau's function using the following code :
f(x,y)=(((x**2)+(y)-11)**2)+(((x)+(y**2)-7)**2)
set xrange [-5:5]
set yrange [-5:5]
set contour base
set cntrparam level discrete 13.59085,25,50,100,150,300,500,1000
set table 'cont.dat'
splot f(x,y)
unset table
reset
set xrange [-5:5]
set yrange [-5:5]
unset key
p './cont.dat' w l lt -1
I get the following plot result:
There are a few problems with the plot which I wish to eliminate:
It shows some horizontal lines in the plot, I don't know why. How can I remove the horizontal lines?
The contour lines are not too smooth. How can I improve there smoothness?
I feel that both the above problems are connected but can't figure out how. Can you please help me understand and hopefully eliminate the problems?
EDIT 1 : I found the answer to question-2, i.e. improving smoothness. I could do it by increasing the isosample. But I still get a lot of horizontal lines as shown in figure below.
But how to remove these horizontal lines? I just want the contour lines for the levels specified.
Here is how you can plot only the contour lines: You must use unset surface, which plots only the contour lines, and view the plot from above with set view map. See also the 2D contour projection plot from the gnuplot demos.
Smoothing can be achieved with set isosamples, but in some way also using e.g. set cntrparam bspline and similar.
So your script becomes:
f(x,y)=(((x**2)+(y)-11)**2)+(((x)+(y**2)-7)**2)
set xrange [-5:5]
set yrange [-5:5]
set contour base
set cntrparam level discrete 13.59085,25,50,100,150,300,500,1000
set isosamples 250
unset surface
set view map
set key out
splot f(x,y)
With the result (using 4.6.3):
I was able to solve both the problems. The solution to Problem-2 I already shared in the edit-1 of question.
For Problem-1, i.e. removing the IsoLines from the contour plot, I should have left the initial blocks of data int he cont.dat files which contain the data for the isolines. Instead, I should have plotted from the Data Block 250 onwards (first 250 blocks of data were from IsoLines because of set isosample 250,250 command).

Resources