Gnuplot yerrorlines xtics issue - gnuplot

I'm using Gnuplot with the 2,2 multiplot environment.
One of my datasets looks like this:
# Avg1. Min1. Max1. Avg2. Min2. Max2.
25 0.049 0.002 0.108 0.051 0.004 0.102
50 0.034 0.005 0.070 0.036 0.004 0.086
100 0.028 0.012 0.044 0.026 0.012 0.054
And I'm using the following script to plot the first graph (I think once I get the first one right I can just repeat the code):
#!/usr/bin/env gnuplot
set term post eps color solid enh
set multiplot layout 2,2 rowsfirst
set grid ytics
set offsets 0.5, 0.5
unset key
set ylabel offset 1,0
set xtics ("25" 1, "50" 2, "100" 3)
### First plot
set tmargin at screen 0.95
set bmargin at screen 0.65
set lmargin at screen 0.10
set rmargin at screen 0.45
set ylabel 'Y-Label Here'
plot 'data.dat' u :2:3:4 w yerrorlines ti 'Title1', \
'' u :5:6:7 w yerrorlines ti 'Title2'
### three other graphs
unset multiplot
And I have three more plots like this. The problem is that my X-axis only shows 25 and 50 (shown below).
I don't know how to fix this. Can anyone help please?
I've tried using 1:2:3:4 instead, but it shows the intermediate X-tics, which I don't want to show.
PlotExample

If you don't specify an explicit column for the x-value, then gnuplot uses the row index, which starts at zero:
set xtics ("25" 0, "50" 1, "100" 2)
plot 'data.dat' u 0:2:3:4 w yerrorlines ti 'Title1'
You can also directly use the values in the first column as xticlabels:
plot 'data.dat' u :2:3:4:xtic(1) w yerrorlines ti 'Title1'

Related

Gnuplot: How to draw an opposing bar plot or pyramid bar diagram

Is it possible to use two positive y-axes with gnuplot? This is just a simple example for the question.
plot.gp:
reset
set style fill solid 1
set boxwidth 0.8 relative
plot 'data1.dat' index 1 using 1:2 with boxes title 'A' ,\
'' index 2 using 1:(-$2) with boxes title 'B'
Instead of using 1:(-$2) I would like to use 1:2 in the last line in plot.gp.
data1.dat:
0.12 0.024
0.15 0.132
0.18 0.241
0.22 0.136
0.12 0.039
0.15 0.219
0.18 0.197
0.22 0.155
From:
To:
Same answer as the one from theoz except that the y2 labels are shifted to the left side of the plot and the set link y2 command is used to generalize the axis inversion.
You can tweak the offset graph -1.03 to superimpose the "0" labels, then delete the duplicate "0" label by changing the y2 tic range to set y2tics 0.1,0.1.
$Data <<EOD
0.12 0.024
0.15 0.132
0.18 0.241
0.22 0.136
0.12 0.039
0.15 0.219
0.18 0.197
0.22 0.155
EOD
set style fill transparent solid 0.5
set boxwidth 0.8 relative
set xzeroaxis ls -1
set yrange[-0.3:0.3]
set ytics 0,0.1
set mytics 2
# Set y2 axis to exact mirror of y1
# Shift tic labels to the left and use right-justified text
set link y2 via -y inv -y
set y2tics 0,0.1
set y2tics offset graph -1.03 right
plot $Data u 1:2 index 0 axis x1y1 w boxes title 'A' ,\
'' u 1:2 index 1 axis x1y2 w boxes title 'B'
Here is a solution with a single plot, however, the y-axis tics are on different sides.
Maybe there is some easy way to get them on the same side.
Code:
### two "positive" y-axes
reset session
$Data <<EOD
0.12 0.024
0.15 0.132
0.18 0.241
0.22 0.136
0.12 0.039
0.15 0.219
0.18 0.197
0.22 0.155
EOD
set style fill transparent solid 0.5
set boxwidth 0.8 relative
set yrange[-0.3:0.3]
set ytics 0,0.1
set mytics 2
set y2range[0.3:-0.3]
set y2tics 0,0.1
set my2tics 2
set y2tics mirror
set xzeroaxis ls -1
plot $Data u 1:2 index 0 axis x1y1 w boxes title 'A' ,\
'' u 1:2 index 1 axis x1y2 w boxes title 'B'
### end of code
Result:
Addition:
Here is a second suggestion with all ytic labels on one side.
A little drawback is that it is not autoscale and you have to set the range and the steps "manually".
It is using the command evaluate (check help evaluate). And real() (check help real) in order to avoid gnuplot's integer division in case the two numbers of the division might be integers.
Code:
### y-axis with two "positive" directions
reset session
$Data <<EOD
0.12 0.024
0.15 0.132
0.18 0.241
0.22 0.136
0.12 0.039
0.15 0.219
0.18 0.197
0.22 0.155
EOD
set style fill transparent solid 0.5
set boxwidth 0.8 relative
set xzeroaxis ls -1
Max = 0.3
Steps = 3
set yrange[-Max:Max]
set ytics () # remove all tics
do for [i=-Steps:Steps] {
myTic = sprintf('set ytics add ("%g" %g)',abs(real(i)/Steps*Max),real(i)/Steps*Max)
eval(myTic)
}
plot $Data u 1:2 index 0 axis x1y1 w boxes lc 3 title 'A' ,\
'' u 1:(-$2) index 1 axis x1y1 w boxes lc 4 title 'B'
### end of code
Result:

Plot a error bar as shaded region in GNUPLOT

I have plotted a graph (X-top axis, Y-bottom axis) with fsteps function in Gnuplot. Next, I tried to add an error bar as a shaded region(transparent) to the graph, but unable to plot it on the graph. Below is the code so far I have tried and also attached the graph.
#!/usr/bin/gnuplot
reset
set border lw 30
set term pngcairo size 10000,10000 font "arial-Bold,130"
set output 'out.png'
unset key
set size ratio 1.2
set style data lines
set xtics format ""
set x2tics nomirror
set ytics out nomirror
set ytics 0,20
set x2label "Vs (km/s)" offset -1.0
set ylabel 'Depth (km)' offset 1.5
set xrange [2.5:4.8]
set yrange [314:0]
set label 3 at 2,120
set key samplen 1.7 at 3.0,135
#
set label 1 '(a)' font "arial-Bold,130" at 0.8,15 right
set label 3 "C3 (MNAI)" center font "arial-Bold,130"
set style fill transparent solid 0.25
set style fill noborder
plot 'MAN.inmd' lc rgb 'blue' lw 35 title "Initial model" with fsteps,\
'MAN.outmd' using 1:2 lc rgb 'red' lw 35 dt"-" title "Inverted model" with fsteps ,\
'MAN.outmd' using 1:($2-$3):($2+$3) with filledcurve lc "blue" notitle,
Example Data for file MAN.outmd X Y Z(Error)
0 3 0
0.4475 3.1 0
0.4475 3.5 0
2.6738 3.6 0.0552
2.6738 5 0.0552
3.8441 5.1 0.0592
3.8441 8 0.0592
3.6302 8.1 0.0395
3.6302 15.935 0.0395
4.5176 15.1 0.041
4.5176 113.296 0.041
4.2443 113.3 0.1024
4.2443 214 0.1024
4.4584 214.1 0.1077
4.4584 314 0.1077
I want output should be as given below (example)
gnuplot can easily fill the area between two "horizontal" curves (i.e. unique x-values), but as far as I know, not between two vertical curves. However, gnuplot can fill some enclosed areas. So, the workaround is to create datapoints which surround the area to be shaded. For this, you "plot" the data into a datablock, once "forward" with x-dx and once "backwards" with x+dx. This can be done easiest if you have the data already in a datablock, because then you can easily loop the data forward and backwards. In case you have your data in a file, see here: gnuplot: load datafile 1:1 into datablock
Code:
### fill between vertical curves
reset session
$Data <<EOD
0 3 0
0.4475 3.1 0
0.4475 3.5 0
2.6738 3.6 0.0552
2.6738 5 0.0552
3.8441 5.1 0.0592
3.8441 8 0.0592
3.6302 8.1 0.0395
3.6302 15.935 0.0395
4.5176 15.1 0.041
4.5176 113.296 0.041
4.2443 113.3 0.1024
4.2443 214 0.1024
4.4584 214.1 0.1077
4.4584 314 0.1077
EOD
# create datablock with circumference of shaded area
set print $XErrorFill
do for [i=1:|$Data|] {
print real(word($Data[i],1))-real(word($Data[i],3)), real(word($Data[i],2))
}
do for [i=|$Data|:1:-1] {
print real(word($Data[i],1))+real(word($Data[i],3)), real(word($Data[i],2))
}
set print
set yrange [:] reverse
set style fill noborder
plot $XErrorFill u 1:2 w filledcurves lc "light-grey" notitle, \
$Data u 1:2 w l lw 1.5 lc rgb "red" notitle
### end of code
Result:

How to use set offset for only 1 of the datasources in gnuplot?

I want to plot two datasources together in gnuplot: one from a datafile, using text as x-data (with xticlabels and errorbars) and another a constant.
I don't want the xticlabels to reach the sides of the graph, so I use "set offset". However, I do want the constant to reach the sides of the graph.
An example gnuplot script:
set terminal pngcairo size 500, 500
file = 'data.txt'
set output 'plot.png'
set xtics rotate by -45
set yrange [0:1]
set offset 0.5,0.5,0,0
plot file using 0:2:3:xticlabels(1) with yerrorbars notitle,\
0.5 notitle
With the associated data.txt file:
"Europe" 0.4 0.03
"North America" 0.8 0.05
"South America" 0.1 0.08
"Asia" 0.7 0.01
"Africa" 0.9 0.03
"Australia" 0.2 0.03
Provides the following plot:
However, I want the following plot:
How can I achieve this?
You can achieve the same result if you are simply setting the xrange[] properly.
In your case when using xticlabels(1), Europe=0 and Australia=5.
So, simply set xrange[-0.5:5.5]. If the number of items (here 6) is unknown beforehand you could get it either via |$Data| or stats $Data and STATS_records.
Code:
### border when using xticlabels()
reset session
$Data <<EOD
"Europe" 0.4 0.03
"North America" 0.8 0.05
"South America" 0.1 0.08
"Asia" 0.7 0.01
"Africa" 0.9 0.03
"Australia" 0.2 0.03
EOD
set xtics rotate by -45
set xrange [-0.5:5.5]
set yrange [0:1]
plot $Data using 0:2:3:xticlabels(1) with yerrorbars notitle,\
0.5 notitle
### end of code
Result:
You could draw the constant as headless arrow:
set arrow from graph 0, first 0.5 to graph 1, first 0.5 nohead lt 1

gnuplot: make only one border thicker in a surface plot

So I am trying to plot a three-dimensional sphere on the first quadrant like this --
I want to make the line BC thicker/bold from the rest. How do I do that?
This is my gnuplot script:
set term wxt 0
set parametric
set urange[0:0.5 * pi]
set vrange[0:0.5 * pi]
r = 1
fx(v,u) = r * cos(v) * cos(u)
fy(v,u) = r * sin(u) * cos(v)
fz(v) = r * sin(v)
set label 1 "A" font "Arial, 15" front at 0.000, 0.900, -0.050
set label 2 "B" font "Arial, 15" front at 0.050, 0.000, 0.900
set label 3 "C" font "Arial, 15" front at 1.050, 0.105, 0.000
set pm3d depthorder border linetype 1 linewidth 0.50
set style fill transparent solid 0.50 border
set palette
set hidden3d
unset colorbox
splot fx(u,v), fy(u,v), fz(u) w pm3d, \
"< echo '0.000 0.000 1.000'" with points pt 7 ps 0.75 lc rgb 'black', \
"< echo '0.000 1.000 0.000'" with points pt 7 ps 0.75 lc rgb 'black', \
"< echo '1.000 0.000 0.000'" with points pt 7 ps 0.75 lc rgb 'black'
set term push
set term pdf enhanced mono
set output "b1.pdf"
replot
unset output
set term pop
system(sprintf("%s", "pdfcrop b1.pdf b1.pdf"))
well, simply plot the line B,C again with lines.
And what is this line in parametric representation? fx(u,0), fy(0,0), fz(u)
splot fx(u,v), fy(u,v), fz(u) w pm3d, \
fx(u,0), fy(0,0), fz(u) w l lw 3 lc rgb "red"
Which gives you something like this... (well, different terminal...)

merging multiple data files to plot in a single graph

extending the question I had asked earlier which can be found here, plotting multiple (x,y) co-ordinates in a single curve with gnuplot. I am trying to plot the bezier curves in gnuplot using 2 different files. Each (x,y) from the first file forms a bezier curve passing through the points from the second file. The first file has the co-ordinates like the following:
x y
0.0 0.5
0.12 0.1
0.16 0.4
0.2 0.35
0.31 0.8
0.34 0.6
0.38 1.0
0.46 0.2
0.51 0.7
0.69 0.9
The second file has the co-ordinates as the following:
x y
0.00 0.7
0.04 0.74073082208
0.08 0.85926917792
0.12 0.9
0.16 0.9
0.2 0.9
0.24 0.749720623086
0.28 0.874229601255
0.32 0.74073082208
0.36 0.8
0.4 0.721178508605
0.44 0.878821491395
0.48 0.761772990545
0.52 0.700774803388
0.56 0.723771273415
0.6 0.789508073675
0.64 0.864014272269
0.68 0.896743348931
Now, how do I merge these two files to plot a single graph. These two files don't have the same number of rows, but I guess that doesn't matter. The first curve would be between (x1,y1) and (x2,y2) from the first file which would continue till (x10,y10). In the curve between (x1,y1) and (x2,y2); the points (x1,y1), (x2,y2) and (x3,y3) from the second file lie.
I followed this link http://t16web.lanl.gov/Kawano/gnuplot/datafile3-e.html to sort and concatenate the two files but got some weird lines which is totally wrong. These values should actually plot Bezier curves but not getting the graph. I have written the following gnuplot script to plot the concatenated data:
set term x11 persist
set title "Animation curves"
set xlabel "Time (secs.)"
set ylabel "Parameter"
set x2label "Phoneme1" offset -35
set pointsize 2
set key off
set style line 2 lt 0 lc 1 lw 2
set xrange [0.0:1.0]
set yrange [0.0:1.3]
plot [0.0:0.8] "< cat -n file1.dat" u 1:2 smooth csplines ls 1, "" u 1:(0.0):(0):(1.3) w vectors nohead ls 2, "" u ($1+0.005):(1):(sprintf("P %d", $0)) w labels, \
"file1.dat" u 1:2 with points, \
"file2.dat" u 1:2 with points, \
I got the following error:
plot "< cat -n file1.dat" u 1:2 smooth csplines ls 1, "" u 1:(0.0):(0):(1.3) w vectors nohead ls 2, "" u ($1+0.005):(1):(sprintf("P %d", $0)) w labels, "file1.dat" u 1:2 with points, "file2.dat" u 1:2 with points,
^
"plot.gp", line 21: Cannot smooth: no data within fixed xrange!
The script below works on my machine. Maybe this is even what you are looking for...
set term x11 persist
set title "Animation curves"
set xlabel "Time (secs.)"
set ylabel "Parameter"
set x2label "Phoneme1" offset -35
set pointsize 2
set key off
set style line 2 lt 0 lc 1 lw 2
set xrange [0.0:1.0]
set yrange [0.0:1.3]
plot [0.0:0.8] "< cat file1.dat file2.dat | sort -n" u 1:2 smooth csplines ls 1, \
"" u 1:(0):(0):2 w vectors nohead ls 2, \
"" u ($1 + 0.005):(1):(sprintf("P %d", $0)) w labels, \
"file1.dat" u 1:2 w p, \
"file2.dat" u 1:2 w p

Resources