How to plot a closed polygon with a spline in gnuplot? - gnuplot

I tried to create a spline around a polygon with gnuplot (see picture 1). Unfortunately without success.
All "smooth " variants do not solve the problem, because most of them sort the x-values and "Bezier" is no spline.
Are there any other ideas?
Spline was created with LibreCalc

The development version of gnuplot uses a general path-following spline in 3D plots. This comes close to what you ask for, but has the limitations that
In order to trigger the path-following spline the points must not lie in a plane (the complicated third entry in the using spec below is just to move the points out of the xy plane).
You won't get rounding at the join point for the start/end of the path
This plot mode is not in a released gnuplot version
It only applies to splot, not splot
Example
unset key
set view map
splot 'spline.dat' using 1:2:($1==1?0:$0) smooth cspline with lines lt 1, \
'' using 1:2:($1==1?0:$0) with points pt 7 lt 1

18 months later
Since I see that this question is still getting views, I am adding an updated answer. The limitations mentioned in the first answer have now been removed. Gnuplot 5.5 (the development version) support a new smoothing option smooth path in both 2D and 3D plots.
Here is the documentation section:
gnuplot> help smooth path
The `smooth path` option generates cubic splines to fit points in the order
they are presented in the input data; i.e. they are not first sorted on x.
This generates a smooth spline through a closed curve or along a trajectory
that contains loops. This smoothing mode is supported for both 2D and 3D
plot commands. As always, a separate curve is created for each set
of points in the input file, where a blank line separates the sets.
Plotting `smooth path with filledcurves closed` will guarantee that each set
of points creates a closed curve. Plotting `smooth path with lines` will
generate a closed curve if the first and last points in the set overlap,
otherwise it will create an open-ended smooth path.
and here is part of a from the online collection:
$LOOP << EOD
1.5 0.5
2.5 0.5
3 1.0
3.5 1.5
4.0 3.5
3.6 4.5
3.0 2.5
4 1.5
5 1.5
EOD
plot $CURVES using 1:2 with points pt 7 ps 2 lc "steelblue" title "original points", \
'' using 1:2 smooth path with lines lt 3 title "smooth path with lines", \
$LOOP using 1:2 with points pt 7 ps 2 lc "steelblue" notitle, \
'' using 1:2 smooth path with lines lt 3 notitle

Related

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

Annoying lines with style filledcurve

I am using gnuplot 5.0 patchlevel 3 and trying to plot a filledcurved generated from a data file. The data file is previously filtered and sorted with the help of awk and sort. A minimal script is
set style fill transparent solid 0.2
plot "<awk -f awkfile filename|sort -g -k 1" u 1:2 with filledcurve y1=90,'' u 1:2 w points
The output fills the curve up to y1=90, which is fine. However every data point is stick with a vertical line runnning from y to y1=90. The line is solid and non-transparent. It ruins the output. How can I get rid of them?

gnuplot : Can the splot command generate impulses in the x-y plane?

Does anyone know if the splot command can be used to generate impulses in the x-y plane?
For example, I have the following segment of gnuplot code;
splot \
\
u, 0, cos(u) linecolor "red" notitle with impulses, \
u, sin(u), 0 linecolor "blue" notitle with impulses, \
u, sin(u), cos(u) linecolor "green" notitle
The first (red) plot successfully generates impulses in the x-z plane, i.e. vertically oriented impulses. The second (blue) plot however, does not generate impulses in the x-y plane, i.e. horizontally oriented impulses, as I would like! Does anyone know how to accomplish this? Furthermore, does anyone know if it possible to use any of the gnuplot iteration commands to do this? Ideally, I would like to have impulses - or something similar like arrows, from the x-axis to the third (green) plot as well.
Thanks in advance.
The blue graph is plotted, but not like you expect. Try changing the 0 to e.g. 0.1:
The reason for this is that in 3D plots, the impulses style always plots lines from z=0 to the actual z value.
What you want is not possible with impulses.
You might be able to adapt this filledcurves example from gnuplotting.org.
The following image was generated with gnuplot. The green lines radiating outward from the x-axis (Theta axis in the image) were implemented using arrows without heads.
I could have simulated impulses for the blue plot using this same approach of arrows without heads, but I have omitted it from the image in order to assist with visual clarity. So, while it appears that impulses can't be used in any orientation other than vertically, arrows can be used for the same effect!
Although this image provides a good visual representation of Euler's formula, I think an even better one is achieved with a 3D "fly-around" of the plot as Theta increases.
The gnuplot code which I used to implement the green arrows, was as such;
set \
\
for [x_new = 0:max_plot_index] \
\
arrow from (x_new * plot_inc),0,0 to (x_new * plot_inc),sin(x_new * plot_inc),cos(x_new * plot_inc) linecolor "green" nohead
where max_plot_index was increased by 1 for every frame of the "fly-around" animation and plot_inc was set to (4 * pi)/100.
I hope someone finds this helpful!

Plotting block data in 3d using different colors and smoothing the lines in Gnuplot or Octave

I am trying to plot (with Gnuplot) some basic 3d data from one file which is pretty much like that:
N M t1 t2 t3 t4
1000 1000 0.05268 0.04711 0.003947 0.003348
1000 2000 0.05743 0.04214 0.007577 0.006486
1000 3000 0.08465 0.04193 0.011329 0.009654
2000 1000 0.10726 0.08845 0.013593 0.012397
2000 2000 0.21065 0.10817 0.026525 0.024390
2000 3000 0.31528 0.16960 0.039772 0.036405
3000 1000 0.25415 0.14845 0.031082 0.026364
3000 2000 0.47345 0.25227 0.060887 0.051840
3000 3000 0.70612 0.36866 0.091311 0.077432
The idea is to plot it in some way I could see t1,t2,t3 and t4 for each N and M. It may be a lot of data to plot in only one graph, I know that. First of all, I have started with t1 plotting this way:
splot 'aux' u 1:2:3 w lp
and I get something like that
I would like to smooth a bit those lines and give them a different color. Is there any way to do something for it? Also any ideas to improve it in any other way would be very nice.
You're right, that is a lot of data. Changing the color of a particular dataset is pretty easy:
splot "dataset" using 1:2:3 w lines linecolor rgb "green"
Note that you can easily overlay multiple plots as follows:
splot "dataset" using 1:2:3 w lines lc rgb "green",\
"" using 1:2:4 w lines lc rgb "red"
A backslash at the end of a line is the gnuplot line-continuation character. Note that it must be the last character on the line. I've also used the pseudo-file "" which is just shorthand for the last file that gnuplot read. Finally, in this second version I used lc instead of linecolor. The gnuplot parser provides a lot of shorthand, although I suspect you already know this since you plotted w lp. (Also, please don't actually choose red and green for your plots. I think one of the biggest flaws in gnuplot is the default first 2 colors are red and green -- 1 in 20 people is red-green colorblind)
Smoothing is another story (unfortunately). plot does support a smooth option
plot "dataset" using 1:2 smooth beizer with lines #see help smooth for a list of options
Unfortunately, it appears that this option doesn't work for splot. At this point, I would write a small utility script to smooth the data in your favorite language using your favorite smoothing algorithm (plot "<utility.script mydata" u 1:2:3 ...). There are other (gnuplot-only) options, but they'd be ugly. What version of gnuplot do you have by the way? The gnuplot version is important to decide the best way to do the smoothing all in gnuplot if you decide that's still necessary.

Resources