values at x-axis fall in between xtics - gnuplot

I am trying to plot a graph where the x-values fall in between xtics.
For example, I want my xtics to be
C72 C73 C74 C75 C76 C77 C78 C79 C80 C81
and the points fall in between C72 C73 ; C73 C74 ; C74 C75 ; and so on.
My data points are
> 2.5 0.17509 C72
> 3.5 0.220434 C73
> 4.5 0.164918 C74
> 5.5 0.172477 C75
> 6.5 0.156145 C76
> 7.5 0.171699 C77
> 8.5 0.165199 C78
> 9.5 0.191207 C79
> 10.5 0.211656 C80
> 11.5 0.202233 C81
I used xticlabels() in the script definitions as below:
#OUTPUT
set terminal pngcairo size 650,450 enhanced dash
set output "xplot_gauche_malto-thermo.png"
set style line 4 lt 4 lw 10 # Please DISABLE pause -1
#MICRO
set macro
labelFONT="font 'arial,22'"
scaleFONT="font 'arial,18'"
scaleFONT2="font 'arial,18'"
keyFONT="font 'arial,18'"
# AXIS DEFINITIONS
set xrange [0:12]
set yrange [0:0.8]
set xtic (2,3,4,5,6,7,8,9,10,11) #scaleFONT2
set ytic #scaleFONT
set boxwidth 0.8
set size square
#PLOT
plot "all_dihedrals_in_layers_malto.dat" using 1:2:xticlabels(3) with linespoints lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title ""
If I use the code as above, to get a plot using only column 1 and 2 from data file (as given above) I get the points fall in between 2-3, 3-4, 4-5 and so on.
Unfortunately if I use "xticlabels()", I don't get the graph as I wanted where the point supposed to fall in between C72-C73, C73-C74, C74-C75 and so on.
Appreciate in advance for any help.
Thanks

try something like this.. (Untested i dont have gnuplot on this machine..)
plot "all_dihedrals_in_layers_malto.dat" using 1:2 with linespoints \
lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title "" ,\
"all_dihedrals_in_layers_malto.dat" using ($1-.5):0/0:xticlabels(3)
of course you could alternately manually key in the labels on the set xtics line..
Edit..had a chance toi try it, the 0/0 or (0/0) does not work. What you need to do is plot some value out of range.. eg:
set yrange [0:]
plot "all_dihedrals_in_layers_malto.dat" using 1:2 with linespoints \
lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title "" ,\
"all_dihedrals_in_layers_malto.dat" using ($1-.5):-1:xticlabels(3) notitle

Related

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 add vertical lines with label using gnuplot?

I have this script to plot data from a CSV file using gnuplot. I want to add 3 vertical lines at different times on the plot to show where I changed the workload of my experiment. I was trying to do it with vector but it was messing the data already plotted. I attached my chart and added manually the vertical blue line as an example of what I want.
#!/usr/bin/gnuplot
# set grid
set key under left maxrows 1
set style line 1 lc rgb '#E02F44' lt 1 lw 1 ps 0.5 pt 7 # input throughput
set style line 2 lc rgb '#FF780A' lt 1 lw 1 ps 0.5 pt 1 # output throughput
set style line 3 lc rgb '#56A64B' lt 1 lw 1 ps 0.5 pt 2 # average processing latency
set style line 4 lc rgb '#000000' lt 1 lw 1 ps 0.5 pt 3 # 99th percentile processing latency
set terminal pdf
set pointintervalbox 0
set datafile separator ','
set output "efficiency-throughput-networkbuffer-baseline-TaxiRideNYC-100Kpersec.pdf"
set title "Throughput vs. processing latency consuming 50K r/s from the New York City (TLC)"
set xlabel "time (minutes)"
set ylabel "Throughput (K rec/sec)"
set y2label "processing latency (seconds)"
set ytics nomirror
set y2tics 0, 1
set xdata time # tells gnuplot the x axis is time data
set timefmt "%Y-%m-%d %H:%M:%S" # specify our time string format
set format x "%M" # otherwise it will show only MM:SS
plot "throughput-latency-increasing.csv" using 1:(column(2)/1000) title "IN throughput" with linespoints ls 1 axis x1y1 \
, "throughput-latency-increasing.csv" using 1:(column(10)/1000) title "OUT throughput" with linespoints ls 2 axis x1y1 \
, "throughput-latency-increasing.csv" using 1:(column(18)/1000) title "avg. latency" with linespoints ls 3 axis x1y2 \
, "throughput-latency-increasing.csv" using 1:(column(26)/1000) title "99th perc. latency" with linespoints ls 4 axis x1y2 \
#, "" using 1:($1):(3):(0) notitle with vectors nohead
My data file is:
"Time","pre_aggregate[0]-IN","pre_aggregate[1]-IN","pre_aggregate[2]-IN","pre_aggregate[3]-IN","pre_aggregate[4]-IN","pre_aggregate[5]-IN","pre_aggregate[6]-IN","pre_aggregate[7]-IN","pre_aggregate[0]-OUT","pre_aggregate[1]-OUT","pre_aggregate[2]-OUT","pre_aggregate[3]-OUT","pre_aggregate[4]-OUT","pre_aggregate[5]-OUT","pre_aggregate[6]-OUT","pre_aggregate[7]-OUT","pre_aggregate[0]-50","pre_aggregate[1]-50","pre_aggregate[2]-50","pre_aggregate[3]-50","pre_aggregate[4]-50","pre_aggregate[5]-50","pre_aggregate[6]-50","pre_aggregate[7]-50","pre_aggregate[0]-99","pre_aggregate[1]-99","pre_aggregate[2]-99","pre_aggregate[3]-99","pre_aggregate[4]-99","pre_aggregate[5]-99","pre_aggregate[6]-99","pre_aggregate[7]-99"
"2020-04-27 10:31:00",1428.05,1274.4666666666667,1364.6166666666666,1384.4666666666667,1327.3,1376.5,1390.9166666666667,1418.35,1428.05,1274.4666666666667,1364.6333333333334,1384.4666666666667,1327.3,1376.5,1390.9166666666667,1418.35,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1
"2020-04-27 10:31:15",1463.5833333333333,1452.3666666666666,1346.7333333333333,1380.3833333333334,1429.4833333333333,1431.6833333333334,1442.85,1425.15,1463.5833333333333,1452.3666666666666,1346.7333333333333,1380.3833333333334,1429.4833333333333,1431.6833333333334,1442.85,1425.15,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1
"2020-04-27 10:31:30",1393.4666666666667,1396.65,1369.55,1381.3833333333334,1336.8,1434.5166666666667,1440.0833333333333,1399.2833333333333,1393.45,1396.65,1369.55,1381.3833333333334,1336.8,1434.5166666666667,1440.0833333333333,1399.2833333333333,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1
"2020-04-27 10:31:45",1404.8833333333334,1448.5333333333333,1313.9,1308.1,1359.6333333333334,1329.5166666666667,1338.4166666666667,1481.5666666666666,1404.8833333333334,1448.5333333333333,1313.9,1308.1,1359.6333333333334,1329.5166666666667,1338.4166666666667,1481.5833333333333,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1
Of course you can plot your lines and labels. In the example below I'm using the newer syntax compared to set xdata time. Which requires timecolumn(1,myTimeFmt) and e.g. set format x "%M" time.
Your date is in double quotes, so you have to define the timeformat using single quotes including the double quotes.
Furthermore, you are using absolute times, so your lines ideally use the same format. You can put it into a datablock. I hope you can adapt the code to your needs.
Code:
### vertical lines with labels on time axis
reset session
$myLines <<EOD
"2020-04-27 10:34:00"
"2020-04-27 10:39:20"
"2020-04-27 10:43:50"
"2020-04-27 10:48:00"
EOD
myTimeFmt = '"%Y-%m-%d %H:%M:%S"'
StartDate = '"2020-04-27 10:30:00"'
EndDate = '"2020-04-27 10:52:00"'
set format x "%M" time
set xrange [strptime(myTimeFmt,StartDate):strptime(myTimeFmt,EndDate)]
yLow = 1.4
yHigh = 3.5
set tmargin screen 0.90
plot '+' u (strptime(myTimeFmt,StartDate)+$0*60):(rand(0)*3+0.5) w l lc rgb "red" notitle, \
$myLines u (timecolumn(1,myTimeFmt)):(yHigh):("Workload\nchanged") w labels right offset -0.5,1.5 not, \
$myLines u (timecolumn(1,myTimeFmt)):(yLow):(0):(yHigh-yLow) w vec lc rgb "blue" lw 2 nohead not
### end of code
Result:

GNUPLOT: First data row not shown in barchar [duplicate]

Am using gnuplot 5.0. with the following as pereamble to each script:
set terminal epslatex 8 color standalone colortext
The issue is that gnuplot is skipping the first row. To my knowledge 4.6 version addressed a similar issue.
Any idea on the problem please?
Example of data file points.dat
4 4
4 -4
-4 4
-4 -4
The first line (4, 4) is skipped. So instead of four points, only three are displayed by gnuplot. Herewith the command am using
#!/bin/bash
set terminal epslatex 8 color standalone colortext
set output outputFileName
set size .55,.55
set pointsize 3.0
##############
# Line styles
##############
set linestyle 1 lt 5 lw 1 #
set linestyle 2 lt 2 lw 1.5
set linestyle 3 lt 6 lw 1 #
set linestyle 4 lt 3 lw 1
set linestyle 5 lt 2 lw 2 #
set linestyle 6 lt 1 lw 2
##################
# Titles
##################
set title 'Image'
set xlabel '$x$' offset 0,0.5
set ylabel '$y$' offset 2,0
set macros
filename_init = sprintf("%s/image_init.dat",dataFileDirectory)
set key autotitle columnhead
set key horiz
set multiplot
plot
filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta" notitle 'initial'
On trick to bypass the issue is to duplicate the first row. Bu this is not practical.
With set key autotitle columnheader gnuplot uses the entries in the first row as key entries, even though for the plot you have specified notitle.
To demonstrate this, consider the following script, using the four data points in points.dat, which you posted:
set terminal pngcairo
set output 'foobar.png'
set offsets 1,1,1,1
set key autotitle columnhead
filename_init = 'points.dat'
set multiplot layout 1,2
plot filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta"
set key noautotitle
plot filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta" title 'initial'
unset multiplot
The result is
So, just remove the line set key autotitle columnhead from your script, and use plot ... title 'initial'. That gives you the expected 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.

gnuplot: first row of data skipped

Am using gnuplot 5.0. with the following as pereamble to each script:
set terminal epslatex 8 color standalone colortext
The issue is that gnuplot is skipping the first row. To my knowledge 4.6 version addressed a similar issue.
Any idea on the problem please?
Example of data file points.dat
4 4
4 -4
-4 4
-4 -4
The first line (4, 4) is skipped. So instead of four points, only three are displayed by gnuplot. Herewith the command am using
#!/bin/bash
set terminal epslatex 8 color standalone colortext
set output outputFileName
set size .55,.55
set pointsize 3.0
##############
# Line styles
##############
set linestyle 1 lt 5 lw 1 #
set linestyle 2 lt 2 lw 1.5
set linestyle 3 lt 6 lw 1 #
set linestyle 4 lt 3 lw 1
set linestyle 5 lt 2 lw 2 #
set linestyle 6 lt 1 lw 2
##################
# Titles
##################
set title 'Image'
set xlabel '$x$' offset 0,0.5
set ylabel '$y$' offset 2,0
set macros
filename_init = sprintf("%s/image_init.dat",dataFileDirectory)
set key autotitle columnhead
set key horiz
set multiplot
plot
filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta" notitle 'initial'
On trick to bypass the issue is to duplicate the first row. Bu this is not practical.
With set key autotitle columnheader gnuplot uses the entries in the first row as key entries, even though for the plot you have specified notitle.
To demonstrate this, consider the following script, using the four data points in points.dat, which you posted:
set terminal pngcairo
set output 'foobar.png'
set offsets 1,1,1,1
set key autotitle columnhead
filename_init = 'points.dat'
set multiplot layout 1,2
plot filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta"
set key noautotitle
plot filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta" title 'initial'
unset multiplot
The result is
So, just remove the line set key autotitle columnhead from your script, and use plot ... title 'initial'. That gives you the expected result.

Resources