Invalid command using stats in gnuplot - statistics

so I'm fairly new to gnuplot and I'm stumped by an invaild command error I get when I try to use stats on a file in gnuplot.
The command in question:
gnuplot> stats "file.dat" using 1
stats "file.dat" using 1
^
invalid command
The file works just fine with the plot command, as in:
gnuplot> plot "file.dat" using 1 with lines
plot "file.dat" using 1 with lines
The data file file.dat looks like this:
125.48 262.31
0.85 215.18
0.85 175.29
0.85 132.11
0.85 78.72
0.74 33.92
0.74 15.98
0.28 9.63
0.28 7.28
0.28 6.24
0.10 5.76
0.10 5.08
0.01 5.02
0.01 4.93
0.01 4.77
Thanks for any help you can offer!

The stats command is available only since version 4.6.0. In previous versions it is possible to access some data information only after plotting. That includes e.g. the exact data ranges, which are available through the variables GPVAL_DATA_X_MIN, GPVAL_DATA_X_MAX etc. Use
plot 'file.dat' using 1
show variables all
To see the available variables. Then you can do something like
plot 'file.dat' using 1
# do something with GPVAL_*
replot

Related

how to fix the problem of the missing color pieces in the colorbox in gnuplot

I met a problem that when I draw a map using gnuplot, there would be a colorbox near the map which looks very weird. I blew up the colorbox and found that there were pieces with missing color, the picture is below. How can I fill the color for the colorbox?
Here are the terminal type and the palette I used in in gnuplot.
set terminal postscript portrait color enhanced 12
set palette defined (-6.0 "#1B66B1",\
-4.8 "#1B66B1",\
-4.8 "#2A85DF",\
-3.6 "#2A85DF",\
-3.6 "#5FA3E7",\
-2.4 "#5FA3E7",\
-2.4 "#95C2EF",\
-1.2 "#95C2EF",\
-1.2 "#C9E0F7",\
-0.120000 "#C9E0F7",\
0.0 "#FFFFFF",\
0.0 "#FFFFFF",\
0.120000 "#F6D5CB",\
1.2 "#F6D5CB",\
1.2 "#EDAB96",\
2.4 "#EDAB96",\
2.4 "#E48062",\
3.6 "#E48062",\
3.6 "#DC562E",\
4.8 "#DC562E",\
4.8 "#AE3F1E",\
6.0 "#AE3F1E")
The ps file has no gaps. If you export it to a png, you may get some artifacts, but it is rather the issue of the ps file handler than the file itself. You can avoid this behavior by asking Gnuplot to produce a simpler eps that won't fail on your favorite eps editor, or you change how you process eps.
change the palette to something more simple
You can define the maximum number of different colors by the maxcolors option of the palette. This generates not more than maxcolors number of possible colors, but it is equidistant.
set terminal postscript portrait color enhanced 12
set o "discrete.eps"
set palette defined (-6.0 "#1B66B1",\
-4.8 "#2A85DF",\
-3.6 "#5FA3E7",\
-2.4 "#95C2EF",\
-1.2 "#C9E0F7",\
0.0 "#FFFFFF",\
1.2 "#F6D5CB",\
2.4 "#EDAB96",\
3.6 "#E48062",\
4.8 "#DC562E",\
6.0 "#AE3F1E") maxcolors 11
set samples 20
set isosamples 20
splot sin(sqrt(x**2+y**2))/sqrt(x**2+y**2) w pm3d
When inspecting the color bar, you can notice the small gap rendered on the png (but not in the eps) after I created the png using Inkscape:
keep the original palette, but change the way you process eps
If you keep the original palette, it generates hundreds of color possibilities, but most of them will collide according to the step-like function you introduced in the color palette.
set terminal postscript portrait color enhanced 12
set o "discrete.eps"
set palette defined (-6.0 "#1B66B1",\
-4.8 "#1B66B1",\
-4.8 "#2A85DF",\
-3.6 "#2A85DF",\
-3.6 "#5FA3E7",\
-2.4 "#5FA3E7",\
-2.4 "#95C2EF",\
-1.2 "#95C2EF",\
-1.2 "#C9E0F7",\
-0.12 "#C9E0F7",\
-0.12 "#FFFFFF",\
0.12 "#FFFFFF",\
0.12 "#F6D5CB",\
1.2 "#F6D5CB",\
1.2 "#EDAB96",\
2.4 "#EDAB96",\
2.4 "#E48062",\
3.6 "#E48062",\
3.6 "#DC562E",\
4.8 "#DC562E",\
4.8 "#AE3F1E",\
6.0 "#AE3F1E")
set samples 20
set isosamples 20
splot sin(sqrt(x**2+y**2))/sqrt(x**2+y**2) w pm3d
set o
set term wxt
Open the eps using different editors to see how it looks like. Use gimp and you'll get something like the fig below.
If you use Inkscape first, which can handle eps natively, it can produce the artifacts.
You can convert the eps to pdf using ghostscript's ps2pdf.
This is more a comment on the answer from DanielTuzes than it is a separate response.
The issue of possibly transparent, possibly off-color, artifacts at the boundary between two solid-fill rectangles is a recurring issue with PostScript/PDF rendering programs and viewers.
This is not really gnuplot's fault (the *.eps can be rendered correctly, it's just that many rendering utilities are glitchy). However, there is a way in gnuplot to suppress these artifacts. In the development version and in the forthcoming gnuplot version 5.4.3 it is selected with a new keyword:
#gnuplot 5.4.3
set pm3d border retrace
Prior to this the same option existed but was undocumented and did not have a separate keyword:
#gnuplot versions prior to 5.4.3
set pm3d border lt -6
This work-around draws extras lines to cover the potential artifacts along fill boundaties, which has the drawback that it makes the output file larger.

gnuplot crash after negative values

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

Gnuplot Bar Chart with Defined Upper Error and Lower Error - Horizontally Shifted? [duplicate]

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

gnuplot histogram errorbar problems

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

Is it possible to put data to plot into gnuplot's prompt?

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

Resources