Multiple y axis sections in a multiplot - gnuplot

I'v got a multiplot 2,2 with 5 lines in each plot, the lines range around the same values from 600-700 on the y value so they're overlapping.
I added +60 +120 +180 and +240 to the y values and it would do the trick but isn't there a way in gnuplot to add multiple sections on the y axes. So I'd plot the first line in the first section, second in the second and so on and each section ranges from 600-700
one of the 4 plots in the multiplot looks like this:
My Code:
set multiplot layout 2,2 title "Spring Summer Fall Winter"
set title 'Spring'
plot 'Data1.csv' every ::614::637 using 2:3 w l title 'CI 0.2',\
"" every ::963::964 using 2:($3+20) w l title 'CI 0.4 [{/Symbol l}ave+20]',\
"" every ::1080::1084 using 2:($3+40) w l title 'CI 0.6 [{/Symbol l}ave+40]',
set title 'Sommer'
plot 'Data2.csv' every ::1074::1155 using 2:3 w l title 'CI 0.2',\
"" every ::2548::2618 using 2:($3+60) w l title 'CI 0.4 [{/Symbol l}ave+60]',\
"" every ::4017::4092 using 2:($3+120) w l title 'CI 0.6 [{/Symbol l}ave+120]',\
"" every ::5580::5655 using 2:($3+180) w l title 'CI 0.8 [{/Symbol l}ave+180]',\
"" every ::7186::7280 using 2:($3+240) w l title 'CI 1.0 [{/Symbol l}ave+240]',
set title 'Fall'
plot 'Data3.csv' every ::43::43 using 2:3 w l title 'CI 0.2',\
"" every ::63::63 using 2:($3+20) w l title 'CI 0.4 [{/Symbol l}ave+20]',\
"" every ::87::87 using 2:($3+40) w l title 'CI 0.6 [{/Symbol l}ave+40]',\
"" every ::135::139 using 2:($3+60) w l title 'CI 0.8 [{/Symbol l}ave+60]',\
"" every ::311::362 using 2:($3+80) w l title 'CI 1.0 [{/Symbol l}ave+80]',
set title 'Winter'
plot 'Data4.csv' using 2:3 every ::788::829 w l title 'CI 0.2',\
"" every ::1256::1268 using 2:($3+20) w l title 'CI 0.4 [{/Symbol l}ave+20]',\
"" every ::1512::1525 using 2:($3+40) w l title 'CI 0.6 [{/Symbol l}ave+40]',\
"" every ::1681::1686 using 2:($3+60) w l title 'CI 0.8 [{/Symbol l}ave+60]',
unset multiplot
unset output
So what I've already got is a Multiplot with one plot for each season:
In every Plot there are up to 5 lines showing some data. Most of the data on the y axes is in an area between 600 and 700 so in order to avoid overlapping lines which are hard to distinguish even with different colors I plotted the first line normally, and then all the other lines with some additional point (+40 +60and so on) so that all the lines are not on the same spot in the plot but on top of each other, so you can compare tendencies and drifts.
What I want to know is if theres a way to simply cut the y axes into up to 5areas each reaching from 600-700so I can plot one line in the top area (600-700) the next one in the are below the one before and so on. So all lines are in the same value field but on top of each other so you can distinguish between them easier but and don't have to mind the +20 or whatever value when looking ad the y axes, since each of those areas on the y axes could have tics and a grid.
Here's an image I made ...

Proof of concept rather than a a complete solution but I think you can use this and start customizing from here:
set multiplot layout 6, 2
set format x "" # no xtic labels
set ytics -4, 2, 4 # adequately spaced, non-overlapping ytic labels
set bmargin 0
plot[][-5:5] "so.dat" every ::0::4 w lp t "spring 1"
plot[][-5:5] "so.dat" every ::5::9 w lp t "summer 1"
set tmargin 0
plot[][-5:5] "so.dat" every ::10::14 w lp t "spring 2"
plot[][-5:5] "so.dat" every ::0::4 w lp t "summer 2"
set bmargin 1
plot[][-5:5] "so.dat" every ::15::19 w lp t "spring 3"
plot[][-5:5] "so.dat" every ::10::14 w lp t "summer 3"
set tmargin 1
set bmargin 0
plot[][-5:5] "so.dat" every ::0::4 w lp t "fall 1"
plot[][-5:5] "so.dat" every ::5::9 w lp t "winter 1"
set tmargin 0
plot[][-5:5] "so.dat" every ::10::14 w lp t "fall 2"
plot[][-5:5] "so.dat" every ::20::24 w lp t "winter 2"
set bmargin 1
plot[][-5:5] "so.dat" every ::5::9 w lp t "fall 3"
plot[][-5:5] "so.dat" every ::10::14 w lp t "winter 3"
unset multiplot
Resulting graph:
Data file so.dat:
1 -1.8351
2 0.6315
3 -1.3365
4 2.1251
5 -0.6708
6 -3.3965
7 -0.2298
8 0.4807
9 -2.4213
10 -0.5998
11 -1.0238
12 -0.2025
13 0.4362
14 -1.1263
15 3.3197
16 0.0337
17 -0.7374
18 1.1504
19 -0.1656
20 -0.4389
21 1.4645
22 1.6538
23 1.6362
24 -2.0363
25 -4.9741

Related

gnuplot set two keys side by side and share a title?

This is my figure:
I want to change the keys to this:
Below is my code, what should I do?
set tmargin at screen 0.995; # top and right usually close to 1
set rmargin at screen 0.995;
set bmargin at screen 0.05;
set lmargin at screen 0.05;
set xr[0:0.24]
set yr[0:0.24]
set xtics border offset 0,0.4 0,0.05,0.2
set ytics border offset 0.8,0 0,0.05,0.2
set xlabel 'RHS' offset 0,3
set ylabel 'LHS' offset 9,0
set key at 0.22,0.1
plot '-' w p ps 2 pt 11 lc 8 title "$\kappa$",\
'-' w p ps 2 pt 7 lc 8,\
'-' w p ps 2 pt 9 lc 8,\
'-' w p ps 2 pt 13 lc 8,\
'-' w p ps 2 pt 10 lc 8,\
'-' w p ps 2 pt 6 lc 8,\
'-' w p ps 2 pt 8 lc 8,\
'-' w p ps 2 pt 12 lc 8,\
x dashtype 2 lc 8
0.208555 0.204212
e
0.108604 0.107899
e
0.055720 0.055651
e
0.037514 0.037498
e
0.208555 0.230125
e
0.108604 0.115062
e
0.055720 0.057531
e
0.037514 0.038354
e
I didn't find a legend on how to do this juxtaposition in the website, hope someone can teach me.
There is the key option maxrows (check help key). With this you can limit the number of rows in the legend, however, depending on whether you need a title for x you may need to play other tricks.
However, the horizontal space between the columns is rather large.
You could reduce the space for the symbol (actually line) in the legend via samplen 0
and use the option reverse, this would place the titles between the symbols, unfortunately not centered.
However, this still doesn't look too good, and even worse if your titles do not have the same length.
If you want to get the symbols closer, you could also use multiplot (check help multiplot) to overlay shifted legends, but I would call this rather cumbersome.
I minimized your script a little.
Script:
### shared title in legend
reset session
$Data <<EOD
0.208555 0.204212
0.108604 0.107899
0.055720 0.055651
0.037514 0.037498
0.208555 0.230125
0.108604 0.115062
0.055720 0.057531
0.037514 0.038354
EOD
set xr[0:0.24]
set yr[0:0.24]
set xlabel 'RHS'
set ylabel 'LHS'
set key at graph 0.9, 0.4
set key maxrows 4 title "Legend title" offset -3,0.2 font ",13"
set key samplen 0 reverse
myPts = "11 7 9 13 10 6 8 12"
myPt(i) = int(word(myPts,i))
myTitles = "title1 title2 title3 title4"
myTitle(i) = i>words(myTitles) ? ' ' : word(myTitles,i)." "
plot for [i=1:8] $Data u 1:2 every :::i-1::i-1 w p ps 2 pt myPt(i) lc 8 ti myTitle(i), \
x w l dt 2 lc 8 notitle
### end of script
Result:
Addition:
Here would be the multiplot solution. Since you are using fixed margins in your original script anyway, it is not too much extra effort. You need to play with the graph coordinates of the second key to get the desired placement.
Script:
### shared title in legend using multiplot
reset session
$Data <<EOD
0.208555 0.204212
0.108604 0.107899
0.055720 0.055651
0.037514 0.037498
0.208555 0.230125
0.108604 0.115062
0.055720 0.057531
0.037514 0.038354
EOD
set xr[0:0.24]
set yr[0:0.24]
set xlabel 'RHS'
set ylabel 'LHS'
set margin 10,5,4,2
set key at graph 0.9, 0.4
set key title "Legend title" offset -3,0.2 font ",13"
set key samplen 0 reverse
myPts = "11 7 9 13 10 6 8 12"
myPt(i) = int(word(myPts,i))
myTitles = "title1 title2 title3 title4"
myTitle(i) = i>words(myTitles) ? ' ' : ' '.word(myTitles,i)
set multiplot
plot for [i=1:4] $Data u 1:2 every :::i-1::i-1 w p ps 2 pt myPt(i) lc 8 ti myTitle(i), \
x w l dt 2 lc 8 notitle
set key at graph 0.8,0.4 title " "
unset border
unset tics
unset xlabel
unset ylabel
plot for [i=5:8] $Data u 1:2 ever :::i-1::i-1 w p ps 2 pt myPt(i) lc 8 ti " "
unset multiplot
### end of script
Result:

Simple heaviside function graphic with gnuplot?

I basically want this (first diagram) done with gnuplot. I've searched and found nothing exactly like this. I can do a good heaviside without the little circles at the end and start of the two lines, but I can't seem to get it with the little circles. Actually, the second diagram would be nice to know too. The third too, but I'm not greedy.
Just for the records and completeness... although you can define a function
H(x) = x<0 ? 0 : 1
If you plot
plot H(x) w l
the line will be continuous at zero and of course without points.
So, another suggestion with just two columns x,y and variable pointtype would be the following.
Code:
### Heaviside function
reset session
$Heaviside <<EOD
-2 0
0 0
0 0.5
0 1
2 1
EOD
set yrange [-1:2]
set ytics 1
unset key
set multiplot layout 3,1
plot $Heaviside u 1:2 w l lc 0, \
'' u 1:($0==1||$0==3?$2:NaN):($0==3?7:6) w p pt var lc 0
plot $Heaviside u 1:2 w l lc 0, \
'' u 1:($0==1||$0==2||$0==3?$2:NaN):($0==2?7:6) w p pt var lc 0
set xrange [0:4]
a = 3
plot $Heaviside u ($1+a):2 w l lc 0, \
'' u ($1+a):($0==1||$0==3?$2:NaN):($0==3?7:6) w p pt var lc 0
unset multiplot
### end of code
Result:
Addition:
A variation with shorter and less confusing plot command, but using 4 columns together with variable pointtype. This will give the same result as above.
Code:
### Heaviside function
reset session
$Heaviside <<EOD
-2 0 NaN NaN
0 0 6 6
0 0.5 NaN 7
0 1 7 6
2 1 NaN NaN
EOD
set yrange [-1:2]
set ytics 1
unset key
set multiplot layout 3,1
plot $Heaviside u 1:2 w l lc 0, \
'' u 1:2:3 w p pt var lc 0
plot $Heaviside u 1:2 w l lc 0, \
'' u 1:2:4 w p pt var lc 0
set xrange [0:4]
a = 3
plot $Heaviside u ($1+a):2 w l lc 0, \
'' u ($1+a):2:3 w p pt var lc 0
unset multiplot
### end of code
Addition 2:
In order to finalize the answer, here is an approach to plot functions containing the Heaviside function.
Instead of plotting from a datablock with fixed x-values (as in the two examples above) it uses the current x-range. Note, for example the syntax plot '+' u 1:(sin($1)) is basically identical with plot sin(x).
Apparently, setting the line color via lc rgb -1 does not plot a line, which can be used here to interrupt the line. You may want to increase the samples, e.g. set samples 300 to avoid a gap between the points and the function.
Code:
### plotting Heaviside function and functions containing Heaviside function
# including line interruption and inclusion/exclusion points
reset session
Heaviside(x,a) = x<a ? 0 : 1 # definition of Heaviside function
array Hpoints[2] = [6,7] # array for plotting "Heaviside points"
Hcolor(x) = (x0=x1, x1=x, x0<a && x1>=a ? -1 : 0xff0000) # set color -1 for line interruption
dx(n) = 1e-3*(2*n-1) # small dx to get y-value of points close to break
f(x,a) = 50/(x**2+2)*cos(4*x) * Heaviside(x,a)
unset key
set multiplot layout 2,1
a = 2.0
set yrange[-1:2]
plot x1=NaN '+' u 1:(Heaviside(x,a)):(Hcolor(x)) w l lc rgb var, \
Hpoints u (a):(Heaviside($1,a)):(Hpoints[$0+1]) w p pt var lc rgb Hcolor(NaN)
a= 0
set samples 300
set yrange[-25:35]
plot x1=NaN '+' u 1:(f(x,a)):(Hcolor(x)) w l lc rgb var, \
Hpoints u (a):(f(a+dx($0),a)):(Hpoints[$0+1]) w p pt var lc rgb Hcolor(NaN)
unset multiplot
### end of code
Result:
I created the following datafile (mind the two empty lines):
-2 0 0 1
0 0 2 1
0 0 0 1
and ran the following gnuplot commands:
set yrange [-2:2]
plot "file" using 1:2 with lines,\
"" using 3:4 with lines, \
"" index 1 using 1:2 with points pointtype 6, \
"" index 1 using 3:4 with points pointtype 7
Fix the colours to your liking.

How to display multiple symbols per line in gnuplot legend?

In gnuplot I have multiple datasets and wish to display on one line of the legend two different symbols. Here's what I currently have:
What I would like is to have to the square and the triangle to be on the same line. I am using the epslatex terminal. Thanks a lot.
You will have to do it by hand.
The most reliable way is probably to make all the key by hand :
Remove all automatic key by issuing unset key
Set custom variables to position your key:
KEY_X=0.1
KEY_Y=0.9
JUMP=0.05
IDX=1
For each plot command, issue before it a corresponding set label (point styles) or set arrow (line styles). E.g.,
set label IDX "a" at graph KEY_X,graph KEY_Y+(IDX-1)*JUMP left point pt 7 lc IDX offset 2
replot x with points pt 7 lc IDX
IDX=IDX+1
Thus you can add an empty label at the desired position when it comes to have two series with the same key.
Just in case this might still be of interest. Here are two ugly workarounds:
reduce the key spacing to 0.5 and plot two NaN dummies with ps 0 and set title "\n".
The symbols will not be (horizontally) next to each other but at least (vertically) close to each other.
set maxrow 3 and samplen 0 and plot one NaN dummy. Although the symbols are (horizontally) next to each other, currently, I don't have an idea how to get them closer to each other.
Code:
### "one" key entry with two symbols
reset session
set samples 20
set multiplot layout 1,2
set key top center spacing 0.5
plot x w p pt 7 ps 1 lc "red" title "a", \
NaN w p ps 0 title "\n", \
x*2 w p pt 5 ps 1 lc "blue" title "b", \
x*3 w p pt 9 ps 1 lc "black" title "\n", \
NaN w p ps 0 title "\n", \
x*4 w l dt 2 lw 1 lc "black" title "c"
set key top center maxrow 3 spacing 1 samplen 0
plot x w p pt 7 ps 1 lc "red" title "a", \
x*2 w p pt 5 ps 1 lc "blue" title "b", \
x*4 w l dt 2 lw 1 lc "black" title "c", \
NaN w p ps 0 title "\n", \
x*3 w p pt 9 ps 1 lc "black" title "\n"
unset multiplot
### end of code
Result:

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"}

Gnuplot 1d plot

I have a text file of the position of particles along the x axis which changes after every collision. Example data.
0 7.5 10 30 30 40
0 9.375 10 32.5 40 40
0 10 10 33.3333 36.6667 40
0 10.25 10.75 34 34 40
0 11.0938 13.2812 28.75 40 40
I am currently trying to plot the data using gnu plot. What I want it to do is have these points along the x axis but instead of plotting the whole file at once I would like gnu plot to plot one line at a time . Furthermore, so the data is identifiable I am trying to plot the points as large markers instead of points. I am struggling to do this and any help would be appreciated.
Firstly, convert the rows to columns using AWK
awk '{for(i=1;i<=NF;i++)a[NR,i]=$i}END{for(i=1;i<=NF;i++){for(j=1;j<=NR;j++)printf a[j,i]"\t";printf "\n"}}' original.dat > particle.dat
#suppose that your input data is original.dat and the output data is particle.dat
The converted data are:
0 0 0 0 0
7.5 9.375 10 10.25 11.0938
10 10 10 10.75 13.2812
30 32.5 33.3333 34 28.75
30 40 36.6667 34 40
40 40 40 40 40
Then, plot your data with the following code in gnuplot:
set border 1
#`set border 1` means only showing the bottom border of the plot. see `help border` for more information
set xtics nomirror
#only show the bottom tics on the x axis and suppress the upper tics of the x axis
unset ytics
#suppress the tics on the y axis
set key outside
#set the legend out side the plot
plot "particle.dat" using 1:(1) with points pointtype 7 pointsize 3 title "particle 1", "" u 2:(2) w p pt 7 ps 3 t "particle 2", "" u 3:(3) w p pt 7 ps 3 t "particle 3", "" u 4:(4) w p pt 7 ps 3 t "particle 4", "" u 5:(5) w p pt 7 ps 3 t "particle 5"
#`using 1:(1)` means use the first column as X and a constant number of 1 as Y. see `help using` for more details
#`u` is short for `using`and `w p pt 7 ps 3` is short for `with points pointtype 7 pointsize 3.
The output of the plot is
I don't think that you have to transpose the data using awk, as each row already contains the data of a single particle.
So, based on the code from DragonHu, I have this:
To generate this plot, I also added lines to connect the points. Also, I used the special column number 0 which just gives the line number in the datafile, starting at 0.
Another trick: Using backslash \, you can split a command to multiple lines. Here is the plot command I used:
plot "particle.dat" using 1:0 with points linetype 1 pointtype 7 pointsize 3 title "particle 1",\
"" u 1:0 notitle w l lt 1,\
"" u 2:0 w p lt 2 pt 7 ps 3 t "particle 2", \
"" u 2:0 notitle w l lt 2,\
"" u 3:0 w p lt 3 pt 7 ps 3 t "particle 3", \
"" u 3:0 notitle w l lt 3,\
"" u 4:0 w p lt 4 pt 7 ps 3 t "particle 4", \
"" u 4:0 notitle w l lt 4,\
"" u 5:0 w p lt 5 pt 7 ps 3 t "particle 5",\
"" u 5:0 notitle w l lt 5
Still, this is not yet the answer, as the question is to plot one set of points at a time. This can be achieved with the following code. It generates five single plots which I dumped into an animated gif figure:
set key center
set yrange[0:1]
set xrange[0:40]
set terminal gif size 600, 200 animate delay 100
set output "animated.gif"
do for [n=0:4] {
set title sprintf("Lineno. %d", n)
plot "particle.dat" every ::n::n using 1:(0) with points pointtype 7 pointsize 3 title "particle 1",\
"" every ::n::n u 2:(0) w p pt 7 ps 3 t "particle 2", \
"" every ::n::n u 3:(0) w p pt 7 ps 3 t "particle 3", \
"" every ::n::n u 4:(0) w p pt 7 ps 3 t "particle 4", \
"" every ::n::n u 5:(0) w p pt 7 ps 3 t "particle 5",\
}
unset output
If single images should be created, it is possible via
set terminal ongcairo
do for [n=0:4] {
set title sprintf("Lineno. %d", n)
set output sprintf("PictureNumber_%d",n)
plot ...
unset output
}

Resources