gnuplot multiple axes (x1y1, x1y2) to plot data from a single file - gnuplot

I am trying to use multiple axes (2 axes x1y1, x1y2) to plot data from a single file. I am having trouble in get the right figure. Any help is greatly appreciated. Thanks.
I am parametrising my gnu plots.
gnuplot -e "datafile='output';
mytitle = 'Latency Vs Packet number (Arrival Rate = 0.3125 pkts/sec, Schedule Rate = 2 pkts/sec) [ES]';
outputname='latvspno_1024.jpg';
x_label='Packet number';
y_label='Packet Latency (Last bit entering to exiting)';
y2_label='Queue Size (in bytes)';
parameter1='Packet Latency';
parameter2='Queue Size'
" scriptv2.plt
This is my scriptv2.plt script that I use for plotting.
set autoscale # scale axes automatically
unset log # remove any log-scaling
unset label # remove any previous labels
set xtic auto # set xtics automatically
set ytic nomirror # set ytics automatically
set y2tic # set ytics automatically
set nokey
set grid
#set term postscript eps#output terminal and file
#set output "qsim.ps"
#set terminal png
#set terminal jpeg medium size 640,480
set terminal jpeg large size 800,600
set output outputname
#set title "Plot of Queue length Vs time (based on config)"
set title mytitle
set xlabel x_label
set ylabel y_label
set y2label y2_label
set key left top
plot datafile axes x1y1 using 1:5 title parameter1 with linespoints pt 7 ps 2,\
datafile axes x1y2 using 1:6 title parameter2 with linespoints pt 7 ps 2
The following is the contents of my datafile (called output)
0 128 0.4 1.4 1 0 256
1 128 0.8 2.4 1.6 128 512
2 128 1.2 3.4 2.2 256 640
3 128 1.6 4.4 2.8 256 896
4 128 2 5.4 3.4 384 1024
5 128 2.4 6.4 4 512 1152
6 128 2.8 7.4 4.6 512 1408
7 128 3.2 8.4 5.2 640 1536
8 128 3.6 9.4 5.8 640 1792
9 128 4 10.4 6.4 768 1792
10 128 4.4 11.4 7 896 1792

I just misplaced the axes position.
plot datafile using 1:5 axes x1y1 title parameter1 with linespoints pt 7 ps 2,\
datafile using 1:6 axes x1y2title parameter2 with linespoints pt 7 ps 2

Related

How to plot points with label and color in Gnuplot?

I want to plot points with individual labels and colors in Gnuplot.
I have a data file a.dat:
###label x y z
1 244.8 18 6.1
2 248.0 10.4 7
3 294.4 6.3 13.7
4 248.0 7.5 8.92
5 240.0 3.69 6.61
6 240.48 3.69 8.92
7 256 5.7 15.8
8 256 7 10.6
9 256 4.1 8.2
10 256 5.1 12.3
The following commands work.
splot 'a.dat' using 2:3:4:1 with labels
set palette model RGB defined (0 'black',1 'blue', 2 'green', 3 'red')
splot 'a.dat' using 2:3:4:($1==3?1:$1==6?2:$1==9?3:0) with points palette
But how can I mix them?
Assuming I understood your question correctly, do you really need a palette if you just want to set only a few specific colors to a few specific points?
You are using two plotting styles with points and with labels you can combine them in one plot command.
Code:
### variable color points
reset session
$Data <<EOD
###label x y z
1 244.8 18 6.1
2 248.0 10.4 7
3 294.4 6.3 13.7
4 248.0 7.5 8.92
5 240.0 3.69 6.61
6 240.48 3.69 8.92
7 256 5.7 15.8
8 256 7 10.6
9 256 4.1 8.2
10 256 5.1 12.3
EOD
myColor(col) = column(col)==3 ? 0x0000ff : \
column(col)==6 ? 0x00ff00 : \
column(col)==9 ? 0xff0000 : 0
set key noautotitle
splot $Data u 2:3:4:(myColor(1)) w p pt 7 lc rgb var, \
'' u 2:3:4:1 w labels offset 0.0,0.7,0.7
### end of code
Result:
Addition: (colored labels)
If you want to have colored labels then change the plot command as follows:
splot $Data u 2:3:4:1:(myColor(1)) w labels tc rgb var
Well, you have to decide:
using only labels it might be difficult to locate the exact position of your data point
using a point and a label without offset it might be diffcult to read the number
Result: (colored label without point)

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 demonstrate LaTeX formula with Gnuplot?

I have attempted to demonstrate a LaTeX formula with Gnuplot 5.0.
But I found that some LaTeX commands are unavailable.
This is my Gnuplot Code:
set termoption enhanced
set title "Title test^a \alpha $\alpha$" font "CMU-Serif, 18"
set xlabel "Month"
set ylabel "Precipitation (mm)"
set xrange [0.5: 12.5]
set xtics 1,1,12
set key
set pointintervalbox 2
plot "08_Data.dat" using 1:2 with linespoints \
linecolor "#FF7800" linewidth 2 pointtype 7 pointsize 0.75 pointinterval -1 \
title "Beijing",\
"08_Data.dat" using 1:3 with linespoints \
linecolor "#00A0DC" linewidth 2 pointtype 7 pointsize 0.75 pointinterval -1 \
title "Shanghai",
set output
pause (-1)
As a result, the LaTeX command test^a works well but the LaTeX \alpha and $\alpha$ don't work:
This is the file: 08_Data.dat :
1 2.5 38.1
2 5.1 58.4
3 10.2 81.3
4 25.4 101.6
5 27.9 114.3
6 71.1 152.4
7 175.3 129.5
8 182.9 132.1
9 48.3 154.9
10 17.8 61.0
11 5.1 50.8
12 2.5 35.6
set term tikz standalone size 7cm, 3cm fontscale 0.6
set ylabel '{\LaTeX\ -- $ \gamma $}'
set xlabel '{\LaTeX\ -- $ x $}'
set output 'example.tex'
plot [0:1] gamma(x) title '$ \gamma(x) $'
unset output
!pdflatex example
Have you tried to directly type in the alpha character in the gnuplot code? I guess gnuplot understands UTF-8.
set title "test^a α α" font "CMU-Serif, 18"
plot x
Result:

Plotting data point statistics (min,max,median)

My file (file.dat) contains the following format
#X Avg Median Min Max
6144 329.355 329.368 329.058899 329.504681
7168 447.697 447.717 447.254499 447.886343
8192 582.577 582.611 581.954116 582.844339
9216 739.178 739.211 738.535311 739.525144
10240 911.311 911.406 910.030310 911.942631
11264 1103.01 1103.08 1101.368124 1103.849248
12288 1312.4 1312.54 1310.437674 1313.122151
How could I plot the Median as a data point and then Min and Max as the errors with candlesticks, errorb or similar showing the intervals?
I have done the following
plot "file.dat" u 1:3:4:5 w yerrorbars pt 3 lc rgb 'red'
But the output graph is not perceptible. Any other ideas?
I guess you should re-think the way of displaying your data.
How should a deviation of less than 0.2% be visible as errorbar on a scale from 300 to 1400?
My suggestion would be to use y-axis to display the median value and y2-axis to display the min/max deviation from the median value, e.g. in percent.
Code:
### yerrorbars
reset session
$Data <<EOD
#X Avg Median Min Max
6144 329.355 329.368 329.058899 329.504681
7168 447.697 447.717 447.254499 447.886343
8192 582.577 582.611 581.954116 582.844339
9216 739.178 739.211 738.535311 739.525144
10240 911.311 911.406 910.030310 911.942631
11264 1103.01 1103.08 1101.368124 1103.849248
12288 1312.4 1312.54 1310.437674 1313.122151
EOD
set key left
set ylabel "Median"
set ytics nomirror
set y2label "Deviation from median in %"
set y2tics nomirror
set errorbars large
plot $Data u 1:3 axes x1y1 w p pt 7 lc rgb "red" title "Median",\
'' u 1:(0):(($4-$3)/$3*100):(($5-$3)/$3*100) axes x1y2 w yerrorbars title "Deviation from median in %"
### end of code
Result:

Gnuplot set background color of data label

I want to set the background of data labels to white! The considered plot is a data plot of the following data (gnuDC.dat):
4 1570.96 1571
8 770.63 771
12 530.33 530
16 385.13 385
24 261.87 262
48 137.71 138
96 81.42 81
The plot command reads:
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p ls 1, \
"gnuDC.dat" using 1:2:3 with labels center offset 2.,0.7 font "Helvetica,14" tc ls 4 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines ls 14
Which gives me:
It looks ok but think one could read the lables better when the would have an white background. Is there an easy way to add the white background for all labels at once?
Here is the whole print file:
set terminal postscript eps size 14cm,10cm enhanced color \
font 'Helvetica,18' linewidth 2
set output 'test.eps'
# Line style for axes
set style line 80 lt 0
set style line 80 lt rgb "#808080"
# Line style for grid
set style line 81 lt 3 # dashed
set style line 81 lt rgb "#808080" lw 0.5 # grey
set grid back linestyle 81
set border 3 back linestyle 80
set xtics nomirror
set ytics nomirror
set style line 100 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5
set style line 200 lc rgb '#a2142f' lt 1 lw 2 pt 7 ps 1.5
set pointintervalbox 0
set style line 1 lc rgb '#0072bd' lt 1 lw 1 pt 9 pi -10 ps 2
set style line 2 lc rgb '#77ac30' lt 1 lw 1 pt 7 pi -10 ps 2
set style line 3 lc rgb '#d95319' lt 1 lw 1 pt 1 pi -10 ps 2
set bmargin 4
set lmargin 5
set rmargin 4
unset title
set size 1,1
#set origin 0,0.27
set xlabel "number of cores, -"
set ylabel "Computational time, s"
set key top right
set key spacing 1.5
set key width -12
set yrange [0:1710]
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p ls 1, \
"gnuDC.dat" using 1:2:3 with labels center offset 2.,0.7 font "Helvetica,14" tc ls 4 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines ls 14
With gnuplot version 5 there is a boxed option which does exactly this: give labels a background and, if you want, also a border. The style is controlled with set style textbox, e.g.
set style textbox opaque noborder
plot ... with labels boxed ...
Applied to your script (with some minor changes due to the changed dash handling since 5.0):
# Line style for axes
set style line 80 lt rgb "#808080"
# Line style for grid
set style line 81 dt 3 # dashed
set style line 81 lt rgb "#808080" lw 0.5 # grey
set grid back linestyle 81
set border 3 back linestyle 80
set tics nomirror
set linetype 1 lc rgb '#0072bd' pt 9 pi -10 ps 2 dt 3
set bmargin 4
set lmargin 5
set rmargin 4
set xlabel "number of cores, -"
set ylabel "Computational time, s"
set key top right
set key spacing 1.5
set key width -12
set yrange [0:1710]
set style textbox opaque noborder
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p lt 1, \
"gnuDC.dat" using 1:2:3 with labels boxed center offset 2.,0.7 font "Helvetica,10" tc ls 1 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines lt 1
No, for versions 4.6 and earlier there isn't an easy way to achieve this.

Resources