I'm trying to plot some experimental data using gnuplot and I need to include data uncertainty in tics' labels. I've figured out that I can manually change every label to "200.0" from "200", but I'm almost sure that there is an easier method. I do hope for your help. :)
Your question is a bit unclear. I understand it like this
$data <<EOD
120 20 250 30
160 20 190 40
200 30 300 23
280 15 260 15
340 25 190 40
EOD
plot $data us 1:3:4:xtic(sprintf("%.1f +/- %.1f", $1, $2)) w err pt 7
See help xticlabel (in contrast to xtics).
Related
I'm encountering a problem using gnuplot to display some distribution data (in the form of bar charts).
Because of the very high values in my data, the smallest ones cannot be displayed.
For example with these values:
10 1
20 4
21 24
22 77
23 177
24 636
25 1700
26 3433
27 5160
28 7462
29 7883
30 6652
31 4155
32 1989
33 797
34 170
Gnuplot do not display the bars corresponding to 10 and 20 because they are way too small comparatively to the maximum.
Is there a way to display them, just a little bit, other than using a logarithmic scale ?
I was especially thinking to a kind of glowing effect at the top of the bars whose values are not null, can it be done using gnuplot ?
Here are the few lines I use to display my data
set style data boxes
set style fill solid 0.1
plot 'distribution.dat'
And here is what I get for the moment:
distribution bar chart
Thanks in advance
Maybe use the "zeroaxis" representation rather than a plot border, and increase the linewidth used to draw boxes.
set style data boxes
set style fill solid 0.1
set xrange [0:*]
set yrange [-100:*]
set xzeroaxis
set yzeroaxis
set tics nomirror
unset key
unset border
plot $DATA linewidth 1.5
I have a data file with 10 lines with 1000 values each line and I'm trying to plot this values with this script
#!/usr/bin/gnuplot -persist
plot "data.dat" using [1:1000] title "" with lines
but I get this error
plot "data.dat" using [1:1000] title "" with lines
^
"./plot.sh", line 3: invalid expression
How can I indiate a interval form the first value to the 1000 value?I't posible to set a diferent random clor to every line?
As #vaettchen pointed out, gnuplot wants data in columns and plotting rows is not straightforward. So, best would be if your data was transposed. Unfortunately, gnuplot has no function to transpose data. So, you have to use external tools to transpose your data.
Although, if your data is 10 lines with 1000 values each, i.e. a strict 10x1000 matrix, you could do something with gnuplot only (see below).
However, if your data is not a strict matrix, e.g. one line has more or less values or one value missing the method below won't work.
The following example (just 5 lines with 7 values each) illustrates plotting columns and plotting rows.
### plotting columns and rows
reset session
set colorsequence classic
$Data <<EOD
11 12 13 14 15 16 17
21 22 23 24 25 26 27
31 32 33 34 35 36 37
41 42 43 44 45 46 47
51 52 53 54 55 56 57
EOD
# get the number of rows
stats $Data u 0 nooutput
RowCount = STATS_records
# do the plot
set multiplot layout 1,2
set title "Plotting columns"
set xlabel "Row no."
set xtics 1
# plot all columns from 1 to *(=autodetection)
plot for [i=1:*] $Data u ($0+1):i w lp pt 7 not
set title "Plotting rows"
set xlabel "Column no."
# plot all rows
plot for [i=0:RowCount-1] $Data matrix u ($1+1):0 every :::i::i w lp pt 7 not
unset multiplot
### end of code
Which results in:
I'm new in gnuplot and sorry that my problem formulation might be unprecise, but I don't know how to find the tools/commnds needed to solve my problem. The code for plotting I would like to integrate in my bash file.
I have a data set like:
285 1 50 7.35092
265 1 50 7.35092
259 1 50 7.35092
258 1 50 7.35092
264 1 50 7.35092
491 5 50 33.97
488 5 50 33.97
495 5 50 33.97
492 5 50 25.1649
495 5 50 33.0725
500 5 50 13.6176
507 5 50 32.2502
489 5 50 33.0725
494 5 50 33.97
491 5 50 33.97
746 10 50 34.6007
746 10 50 34.6007
767 10 50 30.858
745 10 50 34.8789
746 10 50 34.6007
747 10 50 34.6007
758 10 50 34.6007
772 10 50 34.60
I already grouped the data by entering a new line between blocks. I would like to calculate for each block the mean and standard deviation of the 4th column.
Then I would like to plot on the Y axes the mean with the confidence interval (standard deviation) and on the X axes the value from the second column.
Each data block has a unique number in the 2nd column.
Solution: so far I got the values for a point from the first block but while I try to plot I get an error:
#myBash code for plotting.sh
FILEIN=simulationR.txt
rm plotTestR.png
gnuplot << EOF
reset
set terminal png
set output 'plotTestR.png'
set ylabel 'reward'
set xlabel 'Nr of simualtion'
set title 'Simualtio duration'
set grid
stats "$FILEIN" using 4 every :::0::0 nooutput
mean1 = sprintf('%.3f', STATS_mean)
std1 = sprintf('%.3f', STATS_stddev)
stats "$FILEIN" using 2 every :::0::0 nooutput
x1 = sprintf('%.3f', STATS_max)
plot '-' w yerrorbars title std1
x1 mean1 std1
exit
EOF
and the error:
gnuplot> plot '-' w yerrorbars title std1
^
line 1: Bad data on line 1 of file -
Usually, gnuplot isn't made for such data processing tasks. That's best done with an external script, which does the processing and writes to stdout, which can then be feed directly to gnuplot like
plot '< python myscript.py simulationR.txt'
In your example, you can only have fixed data after the plot '-' part, no variable substitution is done here.
However, gnuplot version 5 introduces a new inline data structure, to which you can write your computed values (set print $data).
Note, that the following is a plain gnuplot script, if you want to wrap it in a bash script (which is not necessary, since you can pass variables to a gnuplot script via the command line), then you must escape the $ characters.
FILEIN="simulationR.txt"
system('rm -f plotTestR.png')
reset
set terminal pngcairo
set output 'plotTestR.png'
set ylabel 'reward'
set xlabel 'Nr of simulation'
set title 'Simulation duration'
set grid
set print $data
do for [i=0:2] {
stats FILEIN using 2:4 every :::i::i nooutput
print sprintf("%e %e %e", STATS_max_x, STATS_mean_y, STATS_stddev_y)
}
set autoscale xfix
set offsets 1,1,0,0
plot $data using 1:2:3 w yerrorbars
A further improvement could be to separate two blocks by two blank lines, in which case you can use
stats 'simulationR.txt' using 0 nooutput
to have the number of blocks in the variable STATS_blocks, and you can rewrite the loop as
do for [i=0:STATS_blocks-1] {
stats FILEIN using 2:4 index i nooutput
print sprintf("%e %e %e", STATS_max_x, STATS_mean_y, STATS_stddev_y)
}
I would like to add a horizontal line in my histogram in gnuplot, is that possible?
My histogram has on the x axis: alea1 alea 2 alea3 nalea1 nalea 2 nalea 3
and the y axis goes from 0 to 25.
At 22, I want to add a horizontal line that goes all the way across from one end to the other end of the histogram.
Try adding
, 22 title ""
at the end of your plot command. Works for my test data (file "histo"):
# Year Red Green Blue
1990 33 45 18
1991 35 42 19
1992 34 44 14
1993 37 43 25
1994 47 15 30
1995 41 14 32
1996 42 20 35
1997 39 21 31
plot "histo" u 2 t "Red" w histograms, "" u 3 t "Green" w histograms, "" u 4 t "Blue" w histograms, 22 title ""
(taken from Philip K. Janert, Gnuplot in Action)
The typical way to add horizontal and/or vertical lines is with an arrow
set arrow from x1,y1 to x2,y2 nohead linestyle ...
For a horizontal line, y1 and y2 will be the same. From your question, I'm a little unsure what you mean by "at 22", but I'm guessing you mean that you want to plot the line y=22 on top of your histogram. If that's the case, try this (before your plot command).
set arrow from graph 0,first 22 to graph 1,first 22 nohead lc rgb "#000000" front
Here is my data file
seconds data
(x-axis ( y axis
points) points)
3.880000, 20
3.920000, 10
3.960000, 20
4.000000, 20
4.080000, 20
4.120000, 20
4.570000, 20
4.620000, 10
4.650000, 10
4.690000, 10
4.750000, 20
.
.
.
and so on
I want to plot points in column 2 at positions specified by column 1
ie I want 20 , 10 , 20 20, 20 etc to be present at 3.88 , 3.92, 3.96 on xaxis
Can anybody tell me how to do this ?
Suppose your data is in 1.txt:
plot "1.txt" using 1:2
I know it's been a long time, but for anyone else who stumbles upon this...
For this datafile, you'll also need a set datafile separator ','
e.g.
set datafile separator ','
plot 'data.dat' using 1:2
As a matter of style, it is probably best practice to explicitly comment out the header of the datafile using '#' characters. e.g.
# seconds data
# (x-axis ( y axis
# points) points)
3.880000, 20
3.920000, 10
3.960000, 20
4.000000, 20
4.080000, 20
4.120000, 20
4.570000, 20
4.620000, 10
4.650000, 10
4.690000, 10
4.750000, 20
For this simple example, it works without the comments, but other, more complicated datafiles may not.