Is it possible to put some data into gnuplot right on it's prompt?
Like this:
gnuplot> plot [ 1 2 4 8 ] with lines
Creating a .dat file, saving it, then running gnuplot, plotting, removing file... Sometimes for simple graph that seems too long. Can this be done from gnuplot's prompt?
I believe this will work for you, it should work from a control script, and may work interactively as well:
set xrange [0:5]
set yrange [0:3]
plot "-" using 1:2:3 w yerrorbars
# X Y Z
1.0 1.2 0.2
2.0 1.8 0.3
3.0 1.6 0.2
4.0 1.2 0.2
end
pause -1
This and many other excellent tips I found at this page: http://t16web.lanl.gov/Kawano/gnuplot/datafile2-e.html
Related
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
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
I am trying to plot data with errors e.g
-1.4 -0.2 0.4 6.1 2.5 5.2
I used plot 'data.txt' u 1:4:($1-$2):($1+$3):($4-$6):($4+$5) w xyerrorbars
After it, my plot looks ok for yerror but in xerror not. Points are in good spots but errors are shifted.
I tried to use set format xdata "%f" and so on but it doesn't work
Summary
I'm trying to use error bars with gnuplot but am running into two problems. The first problem is that the error bars are not correctly aligned. The second problem is that I can't specify multiple data sets when using error bars.
First problem: error bar alignment
The first problem is that the error bars are not correctly aligned as can be seen in the following image:
This image was generated from the following script:
set terminal postscript eps enhanced
set yrange [0:20]
set style data histogram
set style histogram errorbars gap 1
set output 'out.eps'
plot "test.dat" using 2:3
and the following test input data
header colA errA colB errB
typeX 10.0 1.0 15.1 1.5
typeY 5.0 0.5 12.1 0.8
The bar error bar at point 0.5 on the x-axis should be associated with first histogram entry rather than being offset. I've tried a few different things, and this simple example is very close to what is shown in the gnuplot 5.0 user manual on page 55 (screenshot below since there isn't an HTML version.
Second problem: specifying multiple data sets with error bars
Using the same test input data from before, the following code will generate a histogram plot with two data sets without using error bars:
set terminal postscript eps enhanced
set yrange [0:20]
set style data histogram
set style histogram
set output 'out.eps'
plot 'test.dat' using 2, '' using 4
But if I try to modify this, as shown below, to generate error bars I get an invalid eps file that can't be displayed.
set terminal postscript eps enhanced
set yrange [0:20]
set style data histogram
set style histogram errorbars
set output 'out2.eps'
plot 'test.dat' using 2:3, '' using 4:5
I have tested this on both OS X with gnuplot 5.0 patchlevel 2 and on Arch Linux with the same version of gnuplot and also with gnuplot 5.0 patchlevel 3
Comment out the first line (header), this solved both problems:
#header colA errA colB errB
typeX 10.0 1.0 15.1 1.5
typeY 5.0 0.5 12.1 0.8
Summary
I'm trying to use error bars with gnuplot but am running into two problems. The first problem is that the error bars are not correctly aligned. The second problem is that I can't specify multiple data sets when using error bars.
First problem: error bar alignment
The first problem is that the error bars are not correctly aligned as can be seen in the following image:
This image was generated from the following script:
set terminal postscript eps enhanced
set yrange [0:20]
set style data histogram
set style histogram errorbars gap 1
set output 'out.eps'
plot "test.dat" using 2:3
and the following test input data
header colA errA colB errB
typeX 10.0 1.0 15.1 1.5
typeY 5.0 0.5 12.1 0.8
The bar error bar at point 0.5 on the x-axis should be associated with first histogram entry rather than being offset. I've tried a few different things, and this simple example is very close to what is shown in the gnuplot 5.0 user manual on page 55 (screenshot below since there isn't an HTML version.
Second problem: specifying multiple data sets with error bars
Using the same test input data from before, the following code will generate a histogram plot with two data sets without using error bars:
set terminal postscript eps enhanced
set yrange [0:20]
set style data histogram
set style histogram
set output 'out.eps'
plot 'test.dat' using 2, '' using 4
But if I try to modify this, as shown below, to generate error bars I get an invalid eps file that can't be displayed.
set terminal postscript eps enhanced
set yrange [0:20]
set style data histogram
set style histogram errorbars
set output 'out2.eps'
plot 'test.dat' using 2:3, '' using 4:5
I have tested this on both OS X with gnuplot 5.0 patchlevel 2 and on Arch Linux with the same version of gnuplot and also with gnuplot 5.0 patchlevel 3
Comment out the first line (header), this solved both problems:
#header colA errA colB errB
typeX 10.0 1.0 15.1 1.5
typeY 5.0 0.5 12.1 0.8