How to change the size of legend-box and size of fonts inside a legend box? - gnuplot

I need to contruct a figure with at least 12 plots in gnuplot epslatex terminal.
The problem is when number of plots becomes larger, the size of legend box becomes larger and it gets overlapped with the plots. How can I control the font size inside a legend box and also the size and positioning of the legend box? My gnuplot script is as below. After compilation of script file , the tex file which is produced could not be compiled.Please advise.
Gnuplot script:
reset
set terminal epslatex color colortext size 11cm,7.5cm standalone
set output "obspI=12.tex"
set style data lines
set multiplot
set log
set key samplen 1 left bottom
set key at 0.02,0.005
set key box lt 1 lc -2 lw 3
set xlabel "$t/N$"
set ylabel '$P_\ell(t)$'
set format y '$10^{%L}$'
set format x '$10^{%L}$'
set xr [0.01:1000]
set yr [0.002:1.5]
plot 'sp_e21_N20I1.dat' u 1:2 w l title '\footnotesize $\ell=1,N=20,E=21$' lc 7 lw 2, \
'sp_e19_N20I1.dat' u 1:2 w l title '\footnotesize $\ell=1,N=20,E=19$' lc 1 lw 2, \
'sp_n_N20I1.dat' u 1:2 w l title '\footnotesize $\ell=1,N=20$', \
'sp_e21_N20I10.dat' u 1:2 w l title '\footnotesize $\ell=10,N=20,E=21$' lw 2, \
'sp_e19_N20I10.dat' u 1:2 w l title '\footnotesize $\ell=10,N=20,E=19$' lw 2, \
'sp_n_N20I10.dat' u 1:2 w l title '\footnotesize $\ell=10,N=20$' lw 2, \
'sp_e21_N40I1.dat' u 1:2 w l title '\footnotesize $\ell=1,N=40,E=21$' lw 2, \
'sp_e19_N40I1.dat' u 1:2 w l title '\footnotesize $\ell=1,N=40,E=19$' lw 2, \
'sp_n_N40I1.dat' u 1:2 w l title '\footnotesize $\ell=1,N=40$', \
'sp_e21_N40I20.dat' u 1:2 w l title '\footnotesize $\ell=20,N=40,E=21$' lw 2, \
'sp_e19_N40I20.dat' u 1:2 w l title '\footnotesize $\ell=20,N=40,E=19$' lw 2, \
'sp_n_N40I20.dat' u 1:2 w l title '\footnotesize $\ell=20,N=40$' lw 2
unset multiplot
set output

The key text size (with or without a box) can be controlled by
set key font ",FONT_SIZE"
(where FONT_SIZE can be 10.5 for example).
For positioning the key box, see
here. There are plenty of options; you can position the key outside the main figure using, e.g.,
set key outside
Height and width of the key box can be controlled by "height" and "width", e.g.:
set key width -12
Hope that helped.

Related

How to make key colour black in Gnuplot

How can I make the key "symbols" black in colour when using palettes?
I think you cannot control this directly, here a workaround:
plot 'MOD1.dat' u 2:3:1 w p pt 7 ps 2 lt black, \
'MOD1.dat' u 2:3:1 w p pt 7 ps 2 lt palette notitle
So, we first plot the data without legend in black, then plot the data points but no legend. The nice thing about this approach is that there is no need to fix the x or y range.
I would just create a dummy line and use notitle on the real lines. Something like
set yrange[0:1]
plot "realdata1.data" u 1:2 w linespoints lt 1 notitle , \
"realdata2.data" u 1:2 w linespoints lt 2 notitle , \
1/0 w linespoints lt 1 lc rgb 'black' title 'Model1', \
1/0 w linespoints lt 1 lc rgb 'black' title 'Model2'
Then replace lt 1 with whatever you have used for style in your current plot. Note that you'll need to use set yrange for gnuplot to accept the dummy curve

Adjusting the scale of every plot in multiplot to be evenly spaced

I am trying to plot multiple graphs using "multiplot" option from gnuplot.
The figure I plot was as below.
I have a small problem but I dont know how to solve this. The problem is regarding the scale of every individual plot. If one notice, scale for every plot a, b, c, d and e is different. For every plot I used different set xrange values. So, I understand gnuplot tried to stretched the plots to fit into the given width limit. Due to that, the scale along horizontal axis do not evenly spaced.
I want the scale to be evenly spaced for every plot especially for horizontal axis.
Below I have given the full code for your view.
How I can get this done?
Many thanks in advance.
#!/usr/bin/gnuplot
########################################################################################
mpl_top = 0.4 #inch outer top margin, title goes here
mpl_bot = 0.7 #inch outer bottom margin, x label goes here
mpl_left = 0.3 #inch outer left margin, y label goes here #vj
mpl_right = 0.8 #inch outer right margin, y2 label goes here #vj
mpl_height = 1.0 #inch height of individual plots
mpl_width = 2.2 #inch width of individual plots #vj
mpl_dx = 0.1 #inch inter-plot horizontal spacing
mpl_dy = 0.4 #inch inter-plot vertical spacing
mpl_ny = 5 #number of rows
mpl_nx = 1 #number of columns
# calculate full dimensions
xsize = mpl_left+mpl_right+(mpl_width*mpl_nx)+(mpl_nx-1)*mpl_dx
ysize = mpl_top+mpl_bot+(mpl_ny*mpl_height)+(mpl_ny-1)*mpl_dy
# placement functions
# rows are numbered from bottom to top
bot(n) = (mpl_bot+(n-1)*mpl_height+(n-1)*mpl_dy)/ysize
top(n) = 1-((mpl_top+(mpl_ny-n)*(mpl_height+mpl_dy))/ysize)
# columns are numbered from left to right
left(n) = (mpl_left+(n-1)*mpl_width+(n-1)*mpl_dx)/xsize
right(n) = 1-((mpl_right+(mpl_nx-n)*(mpl_width+mpl_dx))/xsize)
#=================================================================
#set terminal postscript eps enhanced color dl 2.0 size xsize,ysize "Helvetica" 28
##set encoding iso_8859_1
##set tics scale 1
#set output 'nxm_plot.eps'
set terminal pngcairo size 650,650 enhanced dash #font "Arial-Bold,13" #fontscale 1.20
set output "Fill-Multi-plot-LDP-lyoSystemLast50ns.png"
set encoding iso_8859_1
set offsets
set autoscale fix
set size 1,1
set nokey
# define x-axis settings for all subplots
#set xrange [-30:30]
set yrange [0:3]
set xlabel ''
#set format x ''
set xtic auto
#set xtics 5 #pi
#set mxtics 4
#### VJ DEFINITION
#set style line 4 lt 4 lw 10 # Please DISABLE pause -1
#########################################################################################
set style line 1 lt 1 lw 1.5 lc rgb "red"
set style line 2 lt 3 lw 1.5 lc rgb "red"
set style line 3 lt 5 lw 1.5 lc rgb "red"
set style line 4 lt 1 lw 1.5 lc rgb "black"
set style line 5 lt 3 lw 1.5 lc rgb "black"
set style line 6 lt 5 lw 1.5 lc rgb "black"
set style line 7 lt 1 lw 1.5 lc rgb "green"
set style line 8 lt 3 lw 1.5 lc rgb "green"
set style line 9 lt 5 lw 1.5 lc rgb "green"
set style line 10 lt 1 lw 1.5 lc rgb "blue"
set style line 11 lt 3 lw 1.5 lc rgb "blue"
set style line 12 lt 5 lw 1.5 lc rgb "blue"
set style line 13 lt 1 lw 1.5 lc rgb "magenta"
set style line 14 lt 3 lw 1.5 lc rgb "magenta"
set style line 15 lt 5 lw 1.5 lc rgb "magenta"
set style line 16 lt 1 lw 1.5 lc rgb "#6495ED"
set style line 17 lt 3 lw 1.5 lc rgb "#6495ED"
set style line 18 lt 5 lw 1.5 lc rgb "#6495ED"
###################################################################################################
set macro
#ylabelFONT="font 'arial,16'"
labelFONT="font 'Arial,16'"
scaleFONT="font 'Arial-Bold,14'"
scaleFONtt="font 'Helvetica,10'"
keyFONT="font 'Arial,12'"
#graph="using 1:2 with lines lw 1 "
###################################################################################################
# start plotting
set multiplot
#-----------------------------------------------
# subplot 1-5
# set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
# set horizontal margins for third row (top)
set tmargin at screen top(5)
set bmargin at screen bot(5)
set label "(a)" at -1.5,2.5 #labelFONT
set title ''
unset ylabel
set xrange [-20.0:20.0]
set format y "" #"%-2.1f"
plot "malto12per-000-050ns_only_HEAD.dat" using 1:2 title '1-050ns' w l ls 1 ,\
"malto12per-000-050ns_only_TAIL.dat" using 1:2 title '1-050ns' w l ls 2 ,\
"malto12per-000-050ns_only_WATER.dat" using 1:2 title '1-050ns' w l ls 3 ,\
"malto12per-051-100ns_only_HEAD.dat" using 1:2 title '51-100ns' w l ls 4 ,\
"malto12per-051-100ns_only_TAIL.dat" using 1:2 title '51-100ns' w l ls 5 ,\
"malto12per-051-100ns_only_WATER.dat" using 1:2 title '51-100ns' w l ls 6 ,\
"malto12per-101-150ns_only_HEAD.dat" using 1:2 title '101-150ns' w l ls 7 ,\
"malto12per-101-150ns_only_TAIL.dat" using 1:2 title '101-150ns' w l ls 8 ,\
"malto12per-101-150ns_only_WATER.dat" using 1:2 title '101-150ns' w l ls 9 ,\
"malto12per-151-200ns_only_HEAD.dat" using 1:2 title '151-200ns' w l ls 10 ,\
"malto12per-151-200ns_only_TAIL.dat" using 1:2 title '151-200ns' w l ls 11 ,\
"malto12per-151-200ns_only_WATER.dat" using 1:2 title '151-200ns' w l ls 12 ,\
"malto12per-201-250ns_only_HEAD.dat" using 1:2 title '201-250ns' w l ls 13 ,\
"malto12per-201-250ns_only_TAIL.dat" using 1:2 title '201-250ns' w l ls 14 ,\
"malto12per-201-250ns_only_WATER.dat" using 1:2 title '201-250ns' w l ls 15 ,\
"malto12per-251-300ns_only_HEAD.dat" using 1:2 title '251-300ns' w l ls 16 ,\
"malto12per-251-300ns_only_TAIL.dat" using 1:2 title '251-300ns' w l ls 17 ,\
"malto12per-251-300ns_only_WATER.dat" using 1:2 title '251-300ns' w l ls 18
;
#-----------------------------------------------
# subplot 1-4 at top most
# set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
# set horizontal margins for third row (top)
set tmargin at screen top(4)
set bmargin at screen bot(4)
unset label
set label "(b)" at -1.5,2.5 #labelFONT
set title ''
unset ylabel
set xtics
set xrange [-26.2:26.2]
set format y "" #"%-2.1f"
plot "malto23per-000-050ns_only_HEAD.dat" using 1:2 title '1-050ns' w l ls 1 ,\
"malto23per-000-050ns_only_TAIL.dat" using 1:2 title '1-050ns' w l ls 2 ,\
"malto23per-000-050ns_only_WATER.dat" using 1:2 title '1-050ns' w l ls 3 ,\
"malto23per-051-100ns_only_HEAD.dat" using 1:2 title '51-100ns' w l ls 4 ,\
"malto23per-051-100ns_only_TAIL.dat" using 1:2 title '51-100ns' w l ls 5 ,\
"malto23per-051-100ns_only_WATER.dat" using 1:2 title '51-100ns' w l ls 6 ,\
"malto23per-101-150ns_only_HEAD.dat" using 1:2 title '101-150ns' w l ls 7 ,\
"malto23per-101-150ns_only_TAIL.dat" using 1:2 title '101-150ns' w l ls 8 ,\
"malto23per-101-150ns_only_WATER.dat" using 1:2 title '101-150ns' w l ls 9 ,\
"malto23per-151-200ns_only_HEAD.dat" using 1:2 title '151-200ns' w l ls 10 ,\
"malto23per-151-200ns_only_TAIL.dat" using 1:2 title '151-200ns' w l ls 11 ,\
"malto23per-151-200ns_only_WATER.dat" using 1:2 title '151-200ns' w l ls 12 ,\
"malto23per-201-250ns_only_HEAD.dat" using 1:2 title '201-250ns' w l ls 13 ,\
"malto23per-201-250ns_only_TAIL.dat" using 1:2 title '201-250ns' w l ls 14 ,\
"malto23per-201-250ns_only_WATER.dat" using 1:2 title '201-250ns' w l ls 15 ,\
"malto23per-251-300ns_only_HEAD.dat" using 1:2 title '251-300ns' w l ls 16 ,\
"malto23per-251-300ns_only_TAIL.dat" using 1:2 title '251-300ns' w l ls 17 ,\
"malto23per-251-300ns_only_WATER.dat" using 1:2 title '251-300ns' w l ls 18
;
#-----------------------------------------------
# subplot 1-3
# set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
# set horizontal margins for second row (middle)
set tmargin at screen top(3)
set bmargin at screen bot(3)
unset label
set label "(c)" at -1.5,2.5 #labelFONT
set title ''
set ylabel "Number Density" #labelFONT
set xrange [-24.2:24.2]
set format y "" #"%-1.1f"
plot "bcm25perR-000-050ns_only_HEAD.dat" using 1:2 title '1-050ns' w l ls 1 ,\
"bcm25perR-000-050ns_only_TAIL.dat" using 1:2 title '1-050ns' w l ls 2 ,\
"bcm25perR-000-050ns_only_WATER.dat" using 1:2 title '1-050ns' w l ls 3 ,\
"bcm25perR-051-100ns_only_HEAD.dat" using 1:2 title '51-100ns' w l ls 4 ,\
"bcm25perR-051-100ns_only_TAIL.dat" using 1:2 title '51-100ns' w l ls 5 ,\
"bcm25perR-051-100ns_only_WATER.dat" using 1:2 title '51-100ns' w l ls 6 ,\
"bcm25perR-101-150ns_only_HEAD.dat" using 1:2 title '101-150ns' w l ls 7 ,\
"bcm25perR-101-150ns_only_TAIL.dat" using 1:2 title '101-150ns' w l ls 8 ,\
"bcm25perR-101-150ns_only_WATER.dat" using 1:2 title '101-150ns' w l ls 9 ,\
"bcm25perR-151-200ns_only_HEAD.dat" using 1:2 title '151-200ns' w l ls 10 ,\
"bcm25perR-151-200ns_only_TAIL.dat" using 1:2 title '151-200ns' w l ls 11 ,\
"bcm25perR-151-200ns_only_WATER.dat" using 1:2 title '151-200ns' w l ls 12 ,\
"bcm25perR-201-250ns_only_HEAD.dat" using 1:2 title '201-250ns' w l ls 13 ,\
"bcm25perR-201-250ns_only_TAIL.dat" using 1:2 title '201-250ns' w l ls 14 ,\
"bcm25perR-201-250ns_only_WATER.dat" using 1:2 title '201-250ns' w l ls 15 ,\
"bcm25perR-251-300ns_only_HEAD.dat" using 1:2 title '251-300ns' w l ls 16 ,\
"bcm25perR-251-300ns_only_TAIL.dat" using 1:2 title '251-300ns' w l ls 17 ,\
"bcm25perR-251-300ns_only_WATER.dat" using 1:2 title '251-300ns' w l ls 18
;
#-----------------------------------------------
# subplot 1-2
# set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
# set horizontal margins for second row (middle)
set tmargin at screen top(2)
set bmargin at screen bot(2)
unset label
set label "(d)" at -1.5,2.5 #labelFONT
set title ''
unset ylabel
set xrange [-24.8:24.8]
set format y "" #"%-1.1f"
plot "bcm25perS-000-050ns_only_HEAD.dat" using 1:2 title '1-050ns' w l ls 1 ,\
"bcm25perS-000-050ns_only_TAIL.dat" using 1:2 title '1-050ns' w l ls 2 ,\
"bcm25perS-000-050ns_only_WATER.dat" using 1:2 title '1-050ns' w l ls 3 ,\
"bcm25perS-051-100ns_only_HEAD.dat" using 1:2 title '51-100ns' w l ls 4 ,\
"bcm25perS-051-100ns_only_TAIL.dat" using 1:2 title '51-100ns' w l ls 5 ,\
"bcm25perS-051-100ns_only_WATER.dat" using 1:2 title '51-100ns' w l ls 6 ,\
"bcm25perS-101-150ns_only_HEAD.dat" using 1:2 title '101-150ns' w l ls 7 ,\
"bcm25perS-101-150ns_only_TAIL.dat" using 1:2 title '101-150ns' w l ls 8 ,\
"bcm25perS-101-150ns_only_WATER.dat" using 1:2 title '101-150ns' w l ls 9 ,\
"bcm25perS-151-200ns_only_HEAD.dat" using 1:2 title '151-200ns' w l ls 10 ,\
"bcm25perS-151-200ns_only_TAIL.dat" using 1:2 title '151-200ns' w l ls 11 ,\
"bcm25perS-151-200ns_only_WATER.dat" using 1:2 title '151-200ns' w l ls 12 ,\
"bcm25perS-201-250ns_only_HEAD.dat" using 1:2 title '201-250ns' w l ls 13 ,\
"bcm25perS-201-250ns_only_TAIL.dat" using 1:2 title '201-250ns' w l ls 14 ,\
"bcm25perS-201-250ns_only_WATER.dat" using 1:2 title '201-250ns' w l ls 15 ,\
"bcm25perS-251-300ns_only_HEAD.dat" using 1:2 title '251-300ns' w l ls 16 ,\
"bcm25perS-251-300ns_only_TAIL.dat" using 1:2 title '251-300ns' w l ls 17 ,\
"bcm25perS-251-300ns_only_WATER.dat" using 1:2 title '251-300ns' w l ls 18
;
#-----------------------------------------------
# subplot 1-1
# set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
# set horizontal margins for first row (bottom)
set tmargin at screen top(1)
set bmargin at screen bot(1)
unset label
set label "(e)" at -1.5,2.5 #labelFONT
set title ''
# now set a label and tic marks for the x-axis
set xlabel "Distance / ({\305})" #labelFONT
unset ylabel
set xrange [-24.1:24.1]
set format y "" # "%-1.1f"
plot "bcm25perRS-000-050ns_only_HEAD.dat" using 1:2 title '1-050ns' w l ls 1 ,\
"bcm25perRS-000-050ns_only_TAIL.dat" using 1:2 title '1-050ns' w l ls 2 ,\
"bcm25perRS-000-050ns_only_WATER.dat" using 1:2 title '1-050ns' w l ls 3 ,\
"bcm25perRS-051-100ns_only_HEAD.dat" using 1:2 title '51-100ns' w l ls 4 ,\
"bcm25perRS-051-100ns_only_TAIL.dat" using 1:2 title '51-100ns' w l ls 5 ,\
"bcm25perRS-051-100ns_only_WATER.dat" using 1:2 title '51-100ns' w l ls 6 ,\
"bcm25perRS-101-150ns_only_HEAD.dat" using 1:2 title '101-150ns' w l ls 7 ,\
"bcm25perRS-101-150ns_only_TAIL.dat" using 1:2 title '101-150ns' w l ls 8 ,\
"bcm25perRS-101-150ns_only_WATER.dat" using 1:2 title '101-150ns' w l ls 9 ,\
"bcm25perRS-151-200ns_only_HEAD.dat" using 1:2 title '151-200ns' w l ls 10 ,\
"bcm25perRS-151-200ns_only_TAIL.dat" using 1:2 title '151-200ns' w l ls 11 ,\
"bcm25perRS-151-200ns_only_WATER.dat" using 1:2 title '151-200ns' w l ls 12 ,\
"bcm25perRS-201-250ns_only_HEAD.dat" using 1:2 title '201-250ns' w l ls 13 ,\
"bcm25perRS-201-250ns_only_TAIL.dat" using 1:2 title '201-250ns' w l ls 14 ,\
"bcm25perRS-201-250ns_only_WATER.dat" using 1:2 title '201-250ns' w l ls 15 ,\
"bcm25perRS-251-300ns_only_HEAD.dat" using 1:2 title '251-300ns' w l ls 16 ,\
"bcm25perRS-251-300ns_only_TAIL.dat" using 1:2 title '251-300ns' w l ls 17 ,\
"bcm25perRS-251-300ns_only_WATER.dat" using 1:2 title '251-300ns' w l ls 18
;
#----------------------------------------------------
set size 0.3,0.5
set origin -0.56,-0.35
set bmargin at screen 0
#set key at screen 0.85,screen 0.45 Left reverse spacing 1.0 samplen 1.0 maxcols 1 maxrows 6 #keyFONT
set key at screen 1.00,screen 0.45 maxcols 3 maxrows 6 #keyFONT
#set key center left
set border 0
unset xlabel
unset ylabel
unset label
unset tics
set format x ""
set format y ""
set yrange [0:1]
plot 2 ls 1 t '1-50ns', \
2 ls 4 t '51-100ns', \
2 ls 7 t '101-150ns', \
2 ls 10 t '151-200ns', \
2 ls 13 t '201-250ns', \
2 ls 16 t '251-300ns'
;
unset multiplot
If I understood you correctly, you want the units to have the same length for all graphs. You can dynamically set the margins to obtain this effect with a do loop. Basically you'll need to define the xranges at the beginning and also the maximum range that you will find (you could do this also automatically with a bit more work). The following code should do what you want (read the comments for further info):
# This function returns the ranges for each graph,
# I have only defined 3
range(i)=(i == 1 ? "-20 20" : \
i == 2 ? "-25 25" : \
i == 3 ? "-15 15" : 1/0)
# Number of graphs and maxrange
N = 3; maxrange = 50.
set xtics 5.
set multiplot
# Loop
do for [i=1:N] {
# Set the margins
set tmargin at screen 0.98-(i-1.)/N
set bmargin at screen 0.74-(i-1.)/N
# Set range and calculate total range for graph i
set xrange [word(range(i),1) : word(range(i),2)]
totalrange = word(range(i),2) - word(range(i),1)
# Center the graphs at 0.55 and scale them depending on their range
set lmargin at screen 0.55-0.43*totalrange/maxrange
set rmargin at screen 0.55+0.43*totalrange/maxrange
# Plot
plot sin(x) not
}
Of course there is room for plenty of customization here.
You can define your functions also depending on the label i so they change through the loop:
f(x,i) = (i == 1 ? sin(x) : \
i == 2 ? cos(x) : \
i == 3 ? tan(x) : 1/0)
.
.
.
plot f(x,i)
If you have data files, you can do the same in this way:
datafiles = "data1 data2 data3"
.
.
.
plot word(datafiles,i)
Likewise with the styles and so on:
set style line 1 lw 1
set style line 2 lw 2
set style line 3 lw 3
.
.
.
plot f(x,i) ls i
Finally, if you want complete control (e.g. you are mixing functions and datafile or something else) you can define if statements within the for loop:
.
.
.
if (i == 1) {plot sin(x)}
if (i == 2) {plot cos(x)}
if (i == 3) {plot "data1"}

Same Gnuplot linestyle as in graph in key/legend

I would like to plot a legend/key, which shows the different symbols on the line. Currently my plots look like this:
Unfortunately the symbols (triangle, rectangle and circle) are not shown in the key/legend. How is it possible to add them?
I use the following gnuplot script:
set title tit font "palatino,20"
set xlabel xlbl font "palatino,20"
set ylabel ylbl font "palatino,20"
#set logscale x
set output graphfilename.".pdf"
set terminal pdf
set border linewidth 2
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 5 # --- blue
set style line 2 lc rgb '#00ad60' lt 1 lw 2 pt 7 # red .
set style line 3 lc rgb '#ad0000' lt 1 lw 2 pt 9 # green .
set tics scale 0.8
set key below
plot file1 using ($1/1000):($2/1000000):($3/1000000):($4/1000000) notitle w yerrorbars ls 1, \
'' using ($1/1000):($2/1000000) title "Hlog" w lines ls 1,\
file2 using ($1/1000):($2/1000000):($3/1000000):($4/1000000) notitle w yerrorbars ls 2, \
'' using ($1/1000):($2/1000000) title "Iris" w lines ls 2,\
file3 using ($1/1000):($2/1000000):($3/1000000):($4/1000000) notitle w yerrorbars ls 3, \
'' using ($1/1000):($2/1000000) title "Java" w lines ls 3
Generally, you can get both lines and points, if you plot with the linespoints plotting style:
sc(x) = x*1e-6
plot file1 using ($1/1000):(sc($2)):(sc($3)):(sc($4)) notitle w yerrorbars ls 1 ps 0.5, \
'' using ($1/1000):(sc($2)) title "Hlog" w linespoints ls 1
That draws the points twice, which shouldn't be a problem unless you use transparency. I also shrinked the points which are drawn together with the errorbars to 50%, so you don't get problems with antialiasing.
As another option you could add the title only the the errorbars, in which case the legend would look like |---x---| (i.e. contain also the errorbars):
sc(x) = x*1e-6
plot file1 using ($1/1000):(sc($2)):(sc($3)):(sc($4)) title "Hlog" w yerrorbars ls 1, \
'' using ($1/1000):(sc($2)) notitle w lines ls 1

reduce empty spaces in the plot and make the graph fit optimally

I am plotting multiplot with 11 graphs. I given the code used below:
#!/usr/bin/gnuplot
########################################################################################
#OUTPUT
set size 1.0, 1.0
#POSTCRIPT
set term postscript landscape enhanced color
set output "radial_distribution_function.ps" #
#set terminal postscript portrait enhanced color dashed "Helvetica" 8
#set output "time-density-profile-maltose.ps"
#PNG
#set terminal pngcairo size 650,450 enhanced dash
#set output "multi-plot_gauche_bcMalto-chain2-thermo.png"
# WXT
#set terminal wxt size 900,450 enhanced font 'Arial,10' dashed persist
#set style line 4 lt 4 lw 10 # Please DISABLE pause -1
#########################################################################
set style line 1 lt 1 lc rgb "#FFB6C1" lw 2.0
set style line 2 lt 1 lc rgb "black" lw 2.0
set style line 3 lt 1 lc rgb "green" lw 2.0
set style line 4 lt 1 lc rgb "blue" lw 2.0
set style line 5 lt 1 lc rgb "#8B008B" lw 2.0
set style line 6 lt 1 lc rgb "yellow" lw 2.0
#########################################################################
### START MARCRO
set macro
#ylabelFONT="font 'Arial,16'"
labelFONT="font 'Arial,12'"
scaleFONT="font 'Arial,12'"
keyFONT="font 'Arial,14'"
#graph="using 1:2 with lines lw 1 "
scaleFONT2="font 'Arial,11'"
### END MACRO
set key font ",8"
set key spacing 0.7
unset key
set autoscale # scale axes automatically
set xtic auto #scaleFONT # set xtics automatically
set ytic auto #scaleFONT # set ytics automatically
set xlabel "Distance (Angstrom)" #labelFONT
set ylabel "g(r)" #labelFONT
set xrange [0:10]
set yrange [0:5]
#set title "Density profile for isomaltose"
set multiplot layout 4,3 title ""
# PLOT_1
set label "(a) O11" at 1.5, 4 #labelFONT
plot "maltoLyo12per-ddm_O11-wat_O.dat" using 1:2 w l ls 1 title "{/Symbol b}Mal-C_{12}12%H_{2}O",\
"maltoLyo23per-ddm_O11-wat_O.dat" using 1:2 w l ls 2 title "{/Symbol b}Mal-C_{12}23%H_{2}O",\
"bcmLyo25perR-BMR_O11-wat_O.dat" using 1:2 w l ls 3 title "{/Symbol b}Mal-C_{12}C_{8}(R)25%H_{2}O",\
"bcmLyo25perS-BCS_O11-wat_O.dat" using 1:2 w l ls 4 title "{/Symbol b}Mal-C_{12}C_{8}(S)25%H_{2}O",\
"bchainRS25per-BMR_O11-wat_O.dat" using 1:2 w l ls 5 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(R)25%H_{2}O",\
"bchainRS25per-BMS_O11-wat_O.dat" using 1:2 w l ls 6 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(S)25%H_{2}O"
# PLOT_2
unset label
set label "(b) O12" at 1.5, 4 #labelFONT
plot "maltoLyo12per-ddm_O12-wat_O.dat" using 1:2 w l ls 1 title "{/Symbol b}Mal-C_{12}12%H_{2}O",\
"maltoLyo23per-ddm_O12-wat_O.dat" using 1:2 w l ls 2 title "{/Symbol b}Mal-C_{12}23%H_{2}O",\
"bcmLyo25perR-BMR_O12-wat_O.dat" using 1:2 w l ls 3 title "{/Symbol b}Mal-C_{12}C_{8}(R)25%H_{2}O",\
"bcmLyo25perS-BCS_O12-wat_O.dat" using 1:2 w l ls 4 title "{/Symbol b}Mal-C_{12}C_{8}(S)25%H_{2}O",\
"bchainRS25per-BMR_O12-wat_O.dat" using 1:2 w l ls 5 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(R)25%H_{2}O",\
"bchainRS25per-BMS_O12-wat_O.dat" using 1:2 w l ls 6 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(S)25%H_{2}O"
# PLOT_3
unset label
set label "(c) O13" at 1.5, 4 #labelFONT
plot "maltoLyo12per-ddm_O13-wat_O.dat" using 1:2 w l ls 1 title "{/Symbol b}Mal-C_{12}12%H_{2}O",\
"maltoLyo23per-ddm_O13-wat_O.dat" using 1:2 w l ls 2 title "{/Symbol b}Mal-C_{12}23%H_{2}O",\
"bcmLyo25perR-BMR_O13-wat_O.dat" using 1:2 w l ls 3 title "{/Symbol b}Mal-C_{12}C_{8}(R)25%H_{2}O",\
"bcmLyo25perS-BCS_O13-wat_O.dat" using 1:2 w l ls 4 title "{/Symbol b}Mal-C_{12}C_{8}(S)25%H_{2}O",\
"bchainRS25per-BMR_O13-wat_O.dat" using 1:2 w l ls 5 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(R)25%H_{2}O",\
"bchainRS25per-BMS_O13-wat_O.dat" using 1:2 w l ls 6 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(S)25%H_{2}O"
# PLOT_4
unset label
set label "(d) O14" at 1.5, 4 #labelFONT
plot "maltoLyo12per-ddm_O14-wat_O.dat" using 1:2 w l ls 1 title "{/Symbol b}Mal-C_{12}12%H_{2}O",\
"maltoLyo23per-ddm_O14-wat_O.dat" using 1:2 w l ls 2 title "{/Symbol b}Mal-C_{12}23%H_{2}O",\
"bcmLyo25perR-BMR_O14-wat_O.dat" using 1:2 w l ls 3 title "{/Symbol b}Mal-C_{12}C_{8}(R)25%H_{2}O",\
"bcmLyo25perS-BCS_O14-wat_O.dat" using 1:2 w l ls 4 title "{/Symbol b}Mal-C_{12}C_{8}(S)25%H_{2}O",\
"bchainRS25per-BMR_O14-wat_O.dat" using 1:2 w l ls 5 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(R)25%H_{2}O",\
"bchainRS25per-BMS_O14-wat_O.dat" using 1:2 w l ls 6 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(S)25%H_{2}O"
# PLOT_5
unset label
set label "(e) O15" at 1.5, 4 #labelFONT
plot "maltoLyo12per-ddm_O15-wat_O.dat" using 1:2 w l ls 1 title "{/Symbol b}Mal-C_{12}12%H_{2}O",\
"maltoLyo23per-ddm_O15-wat_O.dat" using 1:2 w l ls 2 title "{/Symbol b}Mal-C_{12}23%H_{2}O",\
"bcmLyo25perR-BMR_O15-wat_O.dat" using 1:2 w l ls 3 title "{/Symbol b}Mal-C_{12}C_{8}(R)25%H_{2}O",\
"bcmLyo25perS-BCS_O15-wat_O.dat" using 1:2 w l ls 4 title "{/Symbol b}Mal-C_{12}C_{8}(S)25%H_{2}O",\
"bchainRS25per-BMR_O15-wat_O.dat" using 1:2 w l ls 5 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(R)25%H_{2}O",\
"bchainRS25per-BMS_O15-wat_O.dat" using 1:2 w l ls 6 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(S)25%H_{2}O"
# PLOT_6
unset label
set label "(f) O16" at 1.5, 4 #labelFONT
plot "maltoLyo12per-ddm_O16-wat_O.dat" using 1:2 w l ls 1 title "{/Symbol b}Mal-C_{12}12%H_{2}O",\
"maltoLyo23per-ddm_O16-wat_O.dat" using 1:2 w l ls 2 title "{/Symbol b}Mal-C_{12}23%H_{2}O",\
"bcmLyo25perR-BMR_O16-wat_O.dat" using 1:2 w l ls 3 title "{/Symbol b}Mal-C_{12}C_{8}(R)25%H_{2}O",\
"bcmLyo25perS-BCS_O16-wat_O.dat" using 1:2 w l ls 4 title "{/Symbol b}Mal-C_{12}C_{8}(S)25%H_{2}O",\
"bchainRS25per-BMR_O16-wat_O.dat" using 1:2 w l ls 5 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(R)25%H_{2}O",\
"bchainRS25per-BMS_O16-wat_O.dat" using 1:2 w l ls 6 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(S)25%H_{2}O"
# PLOT_7
unset label
set label "(g) O22" at 1.5, 4 #labelFONT
plot "maltoLyo12per-ddm_O22-wat_O.dat" using 1:2 w l ls 1 title "{/Symbol b}Mal-C_{12}12%H_{2}O",\
"maltoLyo23per-ddm_O22-wat_O.dat" using 1:2 w l ls 2 title "{/Symbol b}Mal-C_{12}23%H_{2}O",\
"bcmLyo25perR-BMR_O22-wat_O.dat" using 1:2 w l ls 3 title "{/Symbol b}Mal-C_{12}C_{8}(R)25%H_{2}O",\
"bcmLyo25perS-BCS_O22-wat_O.dat" using 1:2 w l ls 4 title "{/Symbol b}Mal-C_{12}C_{8}(S)25%H_{2}O",\
"bchainRS25per-BMR_O22-wat_O.dat" using 1:2 w l ls 5 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(R)25%H_{2}O",\
"bchainRS25per-BMS_O22-wat_O.dat" using 1:2 w l ls 6 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(S)25%H_{2}O"
# PLOT_8
unset label
set label "(h) O23" at 1.5, 4 #labelFONT
plot "maltoLyo12per-ddm_O23-wat_O.dat" using 1:2 w l ls 1 title "{/Symbol b}Mal-C_{12}12%H_{2}O",\
"maltoLyo23per-ddm_O23-wat_O.dat" using 1:2 w l ls 2 title "{/Symbol b}Mal-C_{12}23%H_{2}O",\
"bcmLyo25perR-BMR_O23-wat_O.dat" using 1:2 w l ls 3 title "{/Symbol b}Mal-C_{12}C_{8}(R)25%H_{2}O",\
"bcmLyo25perS-BCS_O23-wat_O.dat" using 1:2 w l ls 4 title "{/Symbol b}Mal-C_{12}C_{8}(S)25%H_{2}O",\
"bchainRS25per-BMR_O23-wat_O.dat" using 1:2 w l ls 5 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(R)25%H_{2}O",\
"bchainRS25per-BMS_O23-wat_O.dat" using 1:2 w l ls 6 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(S)25%H_{2}O"
# PLOT_9
unset label
set label "(i) O24" at 1.5, 4 #labelFONT
plot "maltoLyo12per-ddm_O24-wat_O.dat" using 1:2 w l ls 1 title "{/Symbol b}Mal-C_{12}12%H_{2}O",\
"maltoLyo23per-ddm_O24-wat_O.dat" using 1:2 w l ls 2 title "{/Symbol b}Mal-C_{12}23%H_{2}O",\
"bcmLyo25perR-BMR_O24-wat_O.dat" using 1:2 w l ls 3 title "{/Symbol b}Mal-C_{12}C_{8}(R)25%H_{2}O",\
"bcmLyo25perS-BCS_O24-wat_O.dat" using 1:2 w l ls 4 title "{/Symbol b}Mal-C_{12}C_{8}(S)25%H_{2}O",\
"bchainRS25per-BMR_O24-wat_O.dat" using 1:2 w l ls 5 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(R)25%H_{2}O",\
"bchainRS25per-BMS_O24-wat_O.dat" using 1:2 w l ls 6 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(S)25%H_{2}O"
# PLOT_10
unset label
set label "(j) O25" at 1.5, 4 #labelFONT
plot "maltoLyo12per-ddm_O25-wat_O.dat" using 1:2 w l ls 1 title "{/Symbol b}Mal-C_{12}12%H_{2}O",\
"maltoLyo23per-ddm_O25-wat_O.dat" using 1:2 w l ls 2 title "{/Symbol b}Mal-C_{12}23%H_{2}O",\
"bcmLyo25perR-BMR_O25-wat_O.dat" using 1:2 w l ls 3 title "{/Symbol b}Mal-C_{12}C_{8}(R)25%H_{2}O",\
"bcmLyo25perS-BCS_O25-wat_O.dat" using 1:2 w l ls 4 title "{/Symbol b}Mal-C_{12}C_{8}(S)25%H_{2}O",\
"bchainRS25per-BMR_O25-wat_O.dat" using 1:2 w l ls 5 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(R)25%H_{2}O",\
"bchainRS25per-BMS_O25-wat_O.dat" using 1:2 w l ls 6 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(S)25%H_{2}O"
# PLOT_11
unset label
set label "(k) O26" at 1.5, 4 #labelFONT
unset key
plot "maltoLyo12per-ddm_O26-wat_O.dat" using 1:2 w l ls 1 title "{/Symbol b}Mal-C_{12}12%H_{2}O",\
"maltoLyo23per-ddm_O26-wat_O.dat" using 1:2 w l ls 2 title "{/Symbol b}Mal-C_{12}23%H_{2}O",\
"bcmLyo25perR-BMR_O26-wat_O.dat" using 1:2 w l ls 3 title "{/Symbol b}Mal-C_{12}C_{8}(R)25%H_{2}O",\
"bcmLyo25perS-BCS_O26-wat_O.dat" using 1:2 w l ls 4 title "{/Symbol b}Mal-C_{12}C_{8}(S)25%H_{2}O",\
"bchainRS25per-BMR_O26-wat_O.dat" using 1:2 w l ls 5 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(R)25%H_{2}O",\
"bchainRS25per-BMS_O26-wat_O.dat" using 1:2 w l ls 6 title "{/Symbol b}Mal-C_{12}C_{8}(RS)(S)25%H_{2}O"
unset multiplot
The graph that I get is show here
What I notice from the graph is there is lot of empty space between the graphs. For example between graph (a) and (b) and also between graph (a) and (d). I want to reduce the space between them and make the graph little bigger.
What I should do to reduce the space and optimize the graph size.
Thanks in advance.
Ok, lets start :)
First, your script and your naming of the data files is perfect for iterations. So, you can define a list of file name templates with a placeholder %s, which is later substituted by the actual parameter.
So you first have an iteration over the different O11, O12 etc. values and for each of those a new plot is generated. Then you have a plot for iteration over the file names which are all placed in a single plot.
Using set linetype to define the colors allows you to make use of the automatic line type increment.
Now to your actual question:
I think the best options are to correct the offset of the labels a bit, e.g. with
set ylabel "g(r)" offset 1,0 #labelFONT
which shifts the ylabel by one character unit to the right with respect to the automatically selected position. That should give you a little bigger graph.
If that isn't enough you must start to manually set the margins. I would start by changing only the top and right margins. With e.g.
set tmargin 0
set rmargin 0
the top and right margins will be placed at the boundaries of the respective panels. With e.g. set rmargin 0.5 the right margin is set to a half character width. You must play around with these values.
Here is a shortened script. Note, that I couldn't test it, because I don't have the data files. I hope I didn't make any errors :)
#!/usr/bin/gnuplot
set term postscript landscape enhanced color
set output "radial_distribution_function.ps" #
#########################################################################
set linetype 1 lt 1 lc rgb "#FFB6C1" lw 2.0
set linetype 2 lt 1 lc rgb "black" lw 2.0
set linetype 3 lt 1 lc rgb "green" lw 2.0
set linetype 4 lt 1 lc rgb "blue" lw 2.0
set linetype 5 lt 1 lc rgb "#8B008B" lw 2.0
set linetype 6 lt 1 lc rgb "yellow" lw 2.0
#########################################################################
set macro
labelFONT="font 'Arial,12'"
scaleFONT="font 'Arial,12'"
keyFONT="font 'Arial,14'"
scaleFONT2="font 'Arial,11'"
unset key
set autoscale # scale axes automatically
set xtic auto #scaleFONT # set xtics automatically
set ytic auto #scaleFONT # set ytics automatically
set xlabel "Distance (Angstrom)" #labelFONT
set ylabel "g(r)" offset 1,0 #labelFONT
set xrange [0:10]
set yrange [0:5]
file_tmpls = "maltoLyo12per-ddm_%s-wat_O.dat ".\
"maltoLyo23per-ddm_%s-wat_O.dat ".\
"bcmLyo25perR-BMR_%s-wat_O.dat ".\
"bcmLyo25perS-BCS_%s-wat_O.dat ".\
"bchainRS25per-BMR_%s-wat_O.dat ".\
"bchainRS25per-BMS_%s-wat_O.dat "
par = "O11 O12 O13 O14 O15 O16 O22 O23 O24 O25 O26"
labels = "a b c d e f g h i j k"
label_tmpl = "(%s) %s"
# You must optimize the values, which are given in units of character widths (or heights)
set tmargin 0.5
set rmargin 0.5
#set lmargin 2
#set bmargin 2
set multiplot layout 4,3 title ""
do for [i=1:words(par)] {
set label 1 sprintf("(%s) %s", word(labels, i), word(par, i)) at 1.5, 4 #labelFONT
plot for [f in file_tmpls] sprintf(f, word(par, i)) using 1:2 w l
}
unset multiplot

Thicker lines in the legend of gnuplot

I'm plotting some data curves with gnuplot, and they look like this:
However, the line samples in the legend are too thin. When you have more curves, it becomes hard to distinguish the colors. You can increase the thickness of the curves using "linewidth", e.g., by adding "lw 3" to the plot command, and you'd get this:
However, this increases the thickness everywhere. Is it possible to make the lines thick in the legend only? I know it can be done "the other way", by postprocessing on the output .png file. But is there a direct approach, using some gnuplot setting/wizardry?
Unfortunately, I don't know a way to control the thickness of the lines in the key, since they correspond to the lines being drawn. You can see what you can change by typing help set key in gnuplot.
Using multiplot, you can draw the plot lines first without the key, then draw the key again for 'ghost lines'. Here is a code sample which would do that:
set terminal png color size 800,600
set output 'plot.png'
set multiplot
unset key
plot '../batteries/9v/carrefour.txt' w lp, \
'../batteries/9v/philips.txt' w lp, \
'../batteries/9v/sony.txt' w lp
set key; unset tics; unset border; unset xlabel; unset ylabel
plot [][0:1] 2 title 'Carrefour' lw 4, \
2 title 'Philips' lw 4, \
2 title 'Sony' lw 4
In the second plot command, the function 2 (a constant) is being plotted with a y range of 0 to 1, so it doesn't show up.
I ran across this post and it gave me a critical idea.
The provided solution does not work in multiplot mode, since the second plot command will trigger the second plot, which is most likely not desired.
as a workaround one can set the original data as "notitle", then plot data outside of range with the same linetype and color in different thickness with the desired title. I'll just leave my current example here. It also includes linestyles that i have declared. So i just use the same linestyle (ls) to get the same color but change the thickness on the second line.
# for pngs
set terminal pngcairo size 1600,600 font ',18' enhanced
set output "pic_multi_kenngr_ana.png
set style line 2 lc rgb '#0ce90b' lt 1 lw 1.5 # --- green
set style line 3 lc rgb '#09e0b3' lt 1 lw 1.5 # .
set style line 4 lc rgb '#065fd8' lt 1 lw 1.5 # .
set style line 5 lc rgb '#4e04cf' lt 1 lw 1.5 # .
set style line 6 lc rgb '#c702a9' lt 1 lw 1.5 # .
set style line 7 lc rgb '#bf000a' lt 1 lw 1.5 # --- red
set multiplot layout 1,2
set xtics rotate
set tmargin 5
set xtics 12
set grid xtics
# set axis labels
set ylabel 'T [K]'
set xlabel 'Zeit [h]'
# select range
set xrange [0:48]
set yrange [290.15:306.15]
set title "(a) Bodentemperatur"
set key top right Right
plot 'par_crank_hom01lvls.04.dat' u 1:3 with lines ls 7 notitle,\
'par_crank_str01lvls.16.dat' u 1:3 with lines ls 2 notitle,\
500 t 'z = 4 cm' ls 7 lw 4,\
500 t 'z = 16 cm' ls 2 lw 4
################################################
set title "(b) Bodenwärmestrom an der Oberfläche"
set ylabel 'G [W m^{-2}]'
set yrange[-110:110]
unset key
plot 'par_crank_str01_ghf.dat' u 1:3 with lines
unset multiplot
I hope this will help someone
An even more simple work-around (imho) is to define the colours explicitly and plot each line twice, once with high lw for the key and also with the title to appear in the key, but adding "every ::0::0" which effectively ends up in plotting nothing, and once the normal way. See the following code snippet:
plot data u 0:1 w l linecolor rgb #1b9e77 lw 2 t "",\
data every ::0::0 u 0:1 w l linecolor rgb #1b9e77 lw 4 t "Title"
To expand on the NaN comment by #Svalorzen, the following will graph two lines of width 1 from some datafile.txt with no titles and create matching blank lines with the specified titles and width 5 for the key only:
plot [][]\
NaN title "Title1" w line lt 1 lc 1 lw 5,\
NaN title "Title2" w line lt 1 lc 2 lw 5,\
"datafile.txt" using 1:2 title "" w line lt 1 lc 1 lw 1,\
"datafile.txt" using 1:3 title "" w line lt 1 lc 2 lw 1
I find an answer for this:
Set key linewidth
in your case, must be:
plot '../batteries/9v/carrefour.txt' w l lw 1 linetype 1 notitle, 0/0 linetype 1 linewidth 5 title 'Carrefour'
rep '../batteries/9v/philips.txt' w l lw 1 linetype 2 notitle, 0/0 linetype 2 linewidth 5 title 'Philips'
rep '../batteries/9v/sony.txt' w l lw 1, linetype 3 notitle, 0/0 linetype 3 linewidth 5 title 'Sony'
Try something like:
plot # ... \
keyentry w l lw 1 lc 2 t "Title" # ...
And remove the old keys.

Resources