Shifting of axis title and sub-title in Gnuplot histogram - gnuplot

Mr data file is
# test.dat
# Sample No. Phenol Red Neutral Red Bromophenol Blue Bromocresol Green Mixed Indicator
1 80 69 223 222 130
2 89 62 321 267 160
3 92 67 248 276 147
Gnuplot code is
#
#
###
reset session
###
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 6in,4in
set output "test.eps"
#------------------------------------------------------------------------------
set style line 1 lt 4 lw 1 lc rgb "#4169E1"
set style line 2 lt 4 lw 1 lc rgb "#2E8B57"
set style line 3 lt 5 lw 1 lc rgb "#FF4500"
set style line 4 lt 4 lw 1 lc rgb "#FAD02C"
set style line 5 lt 4 lw 1 lc rgb "#FF0080"
#------------------------------------------------------------------------------
set xtics out scale 1.5
set ytics out scale 1.5
set ytics nomirror
set yrange [0:350]
set key off
set tics font ", 16"
set xlabel "Sample No. " font ",16"
set ylabel "Moisture Content ({/Symbol \155}g of H_{2}O/g of melt)" font ",16"
set key samplen 2 spacing 1.65 font ",14" width -1.0
set key inside left horizontal
set style fill solid border
set style histogram clustered gap 1 title textcolor lt -1
# ----------------------------------------
set rmargin screen 0.9
set lmargin screen 0.1
set bmargin screen 0.4
# ----------------------------------------
set style data histogram
plot \
newhistogram "Direct titration", \
'test.dat' using 2:xtic(1) ls 4 axes x1y1 title "Phenol Red", \
'' u 3 ls 5 axes x1y1 title "Neutral Red", \
newhistogram "Back-titration", \
'test.dat.dat' using 4:xtic(1) ls 1 axes x1y1 title "Bromophenol Blue", \
'' u 5 ls 2 axes x1y1 title "Bromocresol Green", \
'' u 6 ls 3 axes x1y1 title "Mixed Indicator"
# ----------------------------------------
##
Script works fine. I would like to provide more spacing between the tick labels (1,2,3) and the sub-title (Direct titration and Back-titration) as well as spacing between the sub-titles and axis title. How can it be done?

set xlabel offset 0, -1 will shift both the subtitles and the axis title downward by one character height.
set xlabel "\nTEXT" will create a two-line axis label and place TEXT on the second line.
Modifying your xlabel command to be
set xlabel "\nSample No. " font ",16" offset 0,-1
will make both those changes.

Related

Setting the size of title in gnuplot

I have the following script to place in a bash script:
#!/bin/bash
set -e
gnuplot -persist <<-EOFMarker
set pixmap 1 "pathToimage/fig.png" at screen 0.85, 0 width screen 0.15 behind
set rmargin at screen 0.85
# Border line definition
set border lw 1
# Major and Minor grid definition
set style line 100 lt 1 lc rgb "gray" lw 2
set style line 101 lt 0.5 lc rgb "gray" lw 1
set grid mytics ytics ls 100, ls 101
set grid mxtics xtics ls 100, ls 101
set title 'myTitle' font ", 30"
set ylabel 'y [m]' font "Helvetica, 12"
set xlabel 'x [m]' font "Helvetica, 12"
set tics font "Helvetica,10"
plot [-10:10] sin(x),atan(x),cos(atan(x))
EOFMarker
The script is intended to do some plotting and place a logo on the corner of the plot. However, I am not able to change the size of the fonts... I am using gnuplot 5.4.3.
Any advice?
Have you tried to set a terminal? Maybe your default terminal does not support changing the title size.
Using this script, I can set the title size:
set pixmap 1 "linux.png" at screen 0.85, 0 width screen 0.15 behind
set rmargin at screen 0.85
# Border line definition
set border lw 1
# Major and Minor grid definition
set style line 100 lt 1 lc rgb "gray" lw 2
set style line 101 lt 0.5 lc rgb "gray" lw 1
set grid mytics ytics ls 100, ls 101
set grid mxtics xtics ls 100, ls 101
set term png # new
set o "output.png" # new
set title 'myTitle' font ", 30"
set ylabel 'y [m]' font ", 12" # removed font spec
set xlabel 'x [m]' font ", 12" # removed font spec
set tics font ",10"
plot [-10:10] sin(x),atan(x),cos(atan(x))
set o
The output is
If I set the font size to 12, I get

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 crop top and bottom border around my png with Gnuplot?

I have this script :
set title "df -m command test" font ",14"
set terminal pngcairo truecolor size 1600, 900 background rgb "#eff1f0" font "Arial"
set output "/usr/IBMAHS/htdocs/test.png"
set style line 1 \
linecolor rgb '#0060ad' \
linetype 1 linewidth 1 \
pointtype 7 pointsize 1
set style line 2 \
linecolor rgb "red" \
linetype 1 linewidth 1 \
pointtype 7 pointsize 1
set size ratio 0.2
set offsets 0.5,0.5,0,0.5
set key outside center
set datafile separator ","
set ylabel " MB BLOCK " font ",14" offset -1,0
set xlabel " Date " font ",14"
set xtics rotate by 45 offset -0.8,-1.8
set format y "%g"
myLabel(n) = sprintf("%g",n)
plot "/usr/IBMAHS/htdocs/TEST.txt" using 2:xtic(1) with linespoints linestyle 1 title "MB used", \
'' using 3:xtic(1) with linespoints linestyle 2 title " Free space ", \
'' using 0:2:(myLabel($2)) w labels offset 0,-0.5 notitle, \
'' using 0:3:(myLabel($3)) w labels offset 0,1 notitle
This script allow to generate this type of graph :
But the top and bottom border are so big... I would like to reduce them like that :
Can you show me how I can do this ?
You implicitely set the aspect ratio of your output graphic in the second line
set terminal pngcairo truecolor size 1600, 900 background rgb "#eff1f0" font "Arial"
Change the 900 to less to get the desired result.

Equal frame size in a multiplot 3x4

I have the following multiplot
set encoding iso_8859_1
set xtics font "Helvetica,16"
set ytics font "Helvetica,16"
set terminal postscript eps enhanced color size 12in,6in
set grid
set key box vertical width 2 height 0.75 maxcols 1 #spacing 1
load "../estilos.txt"
# TMARGIN = "set tmargin at screen 0.90; set bmargin at screen 0.55"
# BMARGIN = "set tmargin at screen 0.55; set bmargin at screen 0.20"
# LMARGIN = "set lmargin at screen 0.15; set rmargin at screen 0.55"
# RMARGIN = "set lmargin at screen 0.55; set rmargin at screen 0.95"
############################################################################################
set output "_Mult_16R_4Chk_mp.eps"
set title "Minimum number of contention intervals, {/Symbol D}=1" font "Helvetica,17"
set multiplot layout 3,4 columnsfirst
set xlabel ""
set ylabel "T [s]" font "Helvetica,19"
set key top left font "Helvetica,16"
# #TMARGIN #LMARGIN
plot [0:40][0:140] "contention_1/sys-time-4-16-80-15-2.txt" u ($1/60):2 every 2 ls 20 ps 0.35 title "MSL=80%"
set title ""
set key top left font "Helvetica,16"
set ylabel "Queue length [batches]" font "Helvetica,19"
# #BMARGIN; #LMARGIN
plot [0:40][0:70] "contention_1/queue-length-4-16-50-15-1.txt" using ($1/60):2 every 2 with lines ls 20 lw 1.5 title "MSL=50%" ,\
"contention_1/queue-length-4-16-80-15-2.txt" using ($1/60):2 every 2 with lines ls 2200 lw 1.5 title "MSL=80%" ,\
"contention_1/queue-length-4-16-98-15-3.txt" using ($1/60):2 every 2 with lines ls 5550 lw 1.5 title "MSL=98%"
set key bottom right font "Helvetica,16"
set ylabel "Inventory ratio, {/Symbol g}" font "Helvetica,19"
set xlabel "Operation time [minutes]" font "Helvetica,19"
# #BMARGIN; #LMARGIN
plot [0:40][0:1] "contention_1/known-ratio-4-16-50-15-1.txt" using ($1/60):2 every 2 w linespoints ls 20 ps 0.75 lw 1.5 title "MSL=50%" ,\
"contention_1/known-ratio-4-16-80-15-2.txt" using ($1/60):2 every 2 w linespoints ls 2200 ps 0.75 lw 1.5 title "MSL=80%" ,\
"contention_1/known-ratio-4-16-98-15-3.txt" using ($1/60):2 every 2 w linespoints ls 5550 ps 0.75 lw 1.5 title "MSL=98%"
############################################################################################
set title "Minimum number of contention intervals, {/Symbol D}=100" font "Helvetica,17"
set xlabel ""
set ylabel ""
set key top left font "Helvetica,16"
plot [0:40][0:140] "contention_100/sys-time-4-16-80-15-2.txt" u ($1/60):2 every 2 ls 20 ps 0.35 title "MSL=80%"
set title ""
set key top left font "Helvetica,16"
plot [0:40][0:70] "contention_100/queue-length-4-16-50-15-1.txt" using ($1/60):2 every 2 with lines ls 20 lw 1.5 title "MSL=50%" ,\
"contention_100/queue-length-4-16-80-15-2.txt" using ($1/60):2 every 2 with lines ls 2200 lw 1.5 title "MSL=80%" ,\
"contention_100/queue-length-4-16-98-15-3.txt" using ($1/60):2 every 2 with lines ls 5550 lw 1.5 title "MSL=98%"
set key bottom right font "Helvetica,16"
set xlabel "Operation time [minutes]" font "Helvetica,19"
plot [0:40][0:1] "contention_100/known-ratio-4-16-50-15-1.txt" using ($1/60):2 every 2 w linespoints ls 20 ps 0.75 lw 1.5 title "MSL=50%" ,\
"contention_100/known-ratio-4-16-80-15-2.txt" using ($1/60):2 every 2 w linespoints ls 2200 ps 0.75 lw 1.5 title "MSL=80%" ,\
"contention_100/known-ratio-4-16-98-15-3.txt" using ($1/60):2 every 2 w linespoints ls 5550 ps 0.75 lw 1.5 title "MSL=98%"
############################################################################################
set title "Minimum number of contention intervals, {/Symbol D}=200" font "Helvetica,17"
set xlabel ""
set ylabel ""
set key top left font "Helvetica,16"
plot [0:40][0:140] "contention_200/sys-time-4-16-80-15-2.txt" u ($1/60):2 every 2 ls 20 ps 0.35 title "MSL=80%"
set title ""
set key top left font "Helvetica,16"
plot [0:40][0:70] "contention_200/queue-length-4-16-50-15-1.txt" using ($1/60):2 every 2 with lines ls 20 lw 1.5 title "MSL=50%" ,\
"contention_200/queue-length-4-16-80-15-2.txt" using ($1/60):2 every 2 with lines ls 2200 lw 1.5 title "MSL=80%" ,\
"contention_200/queue-length-4-16-98-15-3.txt" using ($1/60):2 every 2 with lines ls 5550 lw 1.5 title "MSL=98%"
set key bottom right font "Helvetica,16"
set xlabel "Operation time [minutes]" font "Helvetica,19"
plot [0:40][0:1] "contention_200/known-ratio-4-16-50-15-1.txt" using ($1/60):2 every 2 w linespoints ls 20 ps 0.75 lw 1.5 title "MSL=50%" ,\
"contention_200/known-ratio-4-16-80-15-2.txt" using ($1/60):2 every 2 w linespoints ls 2200 ps 0.75 lw 1.5 title "MSL=80%" ,\
"contention_200/known-ratio-4-16-98-15-3.txt" using ($1/60):2 every 2 w linespoints ls 5550 ps 0.75 lw 1.5 title "MSL=98%"
############################################################################################
set title "Minimum number of contention intervals, {/Symbol D}=300" font "Helvetica,17"
set xlabel ""
set ylabel ""
# set ylabel "T [s]" font "Helvetica,19"
set key top left font "Helvetica,16"
plot [0:40][0:140] "contention_300/sys-time-4-16-80-15-300-2.txt" u ($1/60):2 every 2 ls 20 ps 0.35 title "MSL=80%"
set title ""
set key top left font "Helvetica,16"
plot [0:40][0:70] "contention_300/queue-length-4-16-50-15-300-1.txt" using ($1/60):2 every 2 with lines ls 20 lw 1.5 title "MSL=50%" ,\
"contention_300/queue-length-4-16-80-15-300-2.txt" using ($1/60):2 every 2 with lines ls 2200 lw 1.5 title "MSL=80%" ,\
"contention_300/queue-length-4-16-98-15-300-3.txt" using ($1/60):2 every 2 with lines ls 5550 lw 1.5 title "MSL=98%"
set key bottom right font "Helvetica,16"
set xlabel "Operation time [minutes]" font "Helvetica,19"
plot [0:40][0:1] "contention_300/known-ratio-4-16-50-15-300-1.txt" using ($1/60):2 every 2 w linespoints ls 20 ps 0.75 lw 1.5 title "MSL=50%" ,\
"contention_300/known-ratio-4-16-80-15-300-2.txt" using ($1/60):2 every 2 w linespoints ls 2200 ps 0.75 lw 1.5 title "MSL=80%" ,\
"contention_300/known-ratio-4-16-98-15-300-3.txt" using ($1/60):2 every 2 w linespoints ls 5550 ps 0.75 lw 1.5 title "MSL=98%"
unset multiplot
The data files are linked here.
The plot looks like this:
which has the information I want to show.
However, the frames are not equal in size. For example, the first row is shorter because it has titles, the middle row of plots is bigger, and the bottom row is also small. The widths of single plots are differents too.
I have seen in this post of Gnuplotting Multiplot – placing graphs next to each other that using set l/b/r/tmargin at screen value is the way to set the sizes of the frames in a multiplot 2x2, but in my case multiplot 3x4 and with tics and separation between single plots result more difficult to achieve.
To my opinion, you probably should forget about set multiplot layout 3,4. Instead, set the sizes and origins of the plots yourself and insert the titles and xlabels as labels at the top and at the bottom. Then use a few parameters to tune your layout. If the code might not be self-explaining enough do not hesitate to ask.
Code:
### customized multiplot
reset session
# Parameters to tune
PlotRows = 3
PlotCols = 4
TitlePosY = 0.98
MultiPlotTop = 0.93
SizeScalingX = 0.90
SizeScalingY = 0.95
MultiPlotBottom = 0.05
XLabelPosY = 0.03
MultiPlotLeft = 0.07
YLabelPosX = 0.02
set lmargin 2
# define origin functions
PlotGridX = (1-MultiPlotLeft)/PlotCols
PlotOriginX(n) = ((n-1)%PlotCols)*PlotGridX + MultiPlotLeft
PlotGridY = (MultiPlotTop-MultiPlotBottom)/PlotRows
PlotOriginY(n) = (PlotRows-1-int((n-1)/PlotCols))*PlotGridY + MultiPlotBottom
# set size
set size SizeScalingX*(1-MultiPlotLeft)/PlotCols, SizeScalingY*(MultiPlotTop+MultiPlotBottom)/PlotRows
# set your titles and labels
TitleStd = "Minimum number of \ncontention intervals, {/Symbol D}="
TitleVar = "1 100 200 300"
XLabelStd = "Operation time [minutes]"
do for [i=1:PlotCols] {
set label i at screen PlotOriginX(i), screen TitlePosY TitleStd.word(TitleVar,i) font "Helvetica,8"
set label i+10 at screen PlotOriginX(i), screen XLabelPosY XLabelStd font "Helvetica,8"
}
YLabels = '"T [s]" "Queue length [batches]" "Inventory ratio, {/Symbol g}"'
do for [i=1:PlotRows] {
set label i+20 at screen YLabelPosX, screen PlotOriginY(i*PlotCols)+PlotGridY*0.5 word(YLabels,i) rotate by 90 center
}
set multiplot
do for [i=1:12] { # do your 3x4 plots here and increase "counter" i after each plot
set origin PlotOriginX(i), PlotOriginY(i)
plot 10**((i-1)/4)*sin(0.1*i*x) notitle
}
unset multiplot
### 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