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

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!

Related

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 plot a closed polygon with a spline in 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

artifacts in transparent fill when plotting data files with gnuplot [duplicate]

I have noticed that Gnuplot produces ugly artefacts when dealing to filled elements.
One instance is in the palette of the next figure:
Another example is when using filledcurves between two curves defined from points in ASCII files. In this case, you can see that rather than a real solid fill between the lines, the area is filled with number of strips, that only become apparent after zooming quite a bit, but that has very strong impact when rastering the image to png or similar:
This seems to be independent on the terminal. I have tried postscrip, pdfcairo and even tikz. Is there anything that can be done to improve this, or is this a hard limitation of Gnuplot?
Unfortunately, this is an artifact due to antialiasing in the document viewer when you have two filled polygons touching each other. This happens with the filledcurves plotting style, which composes the filled area of many quadrangles, as well as with the pm3d style (as you can see in the colorbox, which shows the same artifacts). See also
problematic Moire pattern in image produced with gnuplot pm3d and pdf output. for a concrete demo case.
There is a workaround, which however is very cumbersome. You must generate a filled polygon object with some script, fill that, use stats to determine the ranges, plot an empty plot (see e.g. Gnuplot - how can I get a figure with no point on it ? (I want to have only the axes, the title and the x- and y- labels)).
I assume, that you have a data file with three columns, and you would plot them with
plot 'test.dat' using 1:2:3 with filledcurves
Using the following very crude python script
from __future__ import print_function
from numpy import loadtxt
import sys
M = loadtxt(sys.argv[1])
print('set object 1 polygon ', end='')
for i in range(0,len(M)):
if (i == 0):
print('from {0},{1} '.format(M[i][0], M[i][1]), end='')
else:
print('to {0},{1} '.format(M[i][0], M[i][1]), end='')
for i in range(len(M)-1,-1,-1):
print('to {0},{1} '.format(M[i][0], M[i][2]), end='')
You can plot the filled curve with
# determine the autoscaling ranges
set terminal push
set terminal unknown
plot 'test.dat' using 1:2, '' using 1:3
set terminal pop
set xrange [GPVAL_X_MIN:GPVAL_X_MAX]
set yrange [GPVAL_Y_MIN:GPVAL_Y_MAX]
eval(system('python script.py test.dat'))
set object 1 polygon fillstyle solid noborder fillcolor rgb 'red'
plot NaN notitle
That, doesn't yet cover the problem with the jagged colorbox :(

Gnuplot: line opacity / transparency?

I am using Gnuplot to successfully plot some time series data. However, the series are fairly dense (10,000's of samples in about 5 inches of space), and when I plot multiple series, it is hard to see underneath the series that was plotted on top. Is there any way to make the lines have a bit of opacity or transparency (i.e. make the line transparent so underneath lines are visible)?
Excel has this capability, but I would much prefer to use Gnuplot.
Below is a sample of what I'm talking about. You can't see the red lines under the green lines. I would actually like to add a third time series. I am plotting with the command:
plot [][-3:3] 'samples_all.csv' using 1:7 title 'horizontal' w l ls 1, '' using 1:8 title 'vertical' w l ls 2"
Good news! This has been implemented in gnuplot. Example syntax is
plot x lw 10, -x lw 10 lc rgb "#77000000"
This will plot x as a red line and -x as a transparent black line (it looks gray). The first pair of two characters in the rgb specification define the alpha (transparency) channel ("#AARRGGBB"). The normal syntax ("#RRGGBB") still works.
old (gnuplot < 5.0 or so) answer for reference:
If you want to make lines plotted for time series data, the answer is no (see discussion here). You can't set a line style to be transparent. Transparency only works for filling under curves, and it has to be printed to the right terminal type.
I ran into this problem myself recently, I hope this feature will be added in a future version of gnuplot.
This may be what you're looking for.

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