I've used the following script to generate a plot and the result is shown in the figure below. It is hard to see, but the xlabel, ylabel, title and tic numbers have actually been drawn over and over again each time a plot function was called while in multiplot. In ideas how I can avoid this and just plot the graph without anything else? If I unset the title, tics etc and then plot, then the graph does not plot in the same area as the frame and petrudes into where the left y-axis is.
#set datafile separator ' '
set samples 1000
set term tikz size 17cm,10cm dashed
set out 'MosfetClassAbPower.tex'
unset key
set border lw 2
set style fill transparent solid 0.5 noborder
set title 'MOSFET $\mathrm{I_D}$ Vs Time'
set ylabel 'Drain Current [$\mu$A]'
set xlabel 'Time [ms]'
set xrange [0:4]
set xtics 0,0.5,4
set mxtics 4
set yrange [-50:450]
set mytics 4
set rmargin 5
set label 1 '\SI{60}{\micro\ampere}' at 4.02,60
set multiplot
set grid mxtics mytics lt -1 lc rgb 'gray90'
plot NaN notitle
unset grid
set grid xtics ytics lt -1 lc rgb 'gray70'
plot NaN notitle
unset grid
plot NaN notitle
Id(x) = 347*sin(2*3.14*x) + 60
ID(x) = Id(x) >= 0 ? Id(x) : 0
plot ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
60 w lines lt 2 lw 3 lc rgb 'gray60',\
ID(x) w lines lt 1 lw 5 lc rgb 'navy'
plot NaN notitle
unset multiplot
set out
My attempt at preventing the curve from protruding over the frame.
Edit:
reset
#set term tikz size 17cm,10cm dashed standalone header '\usepackage{siunitx}'
#set out 'MosfetClassAbPower.tex'
#TSCALE = 1.0
set terminal pdfcairo dashed
set out 'MosfetClassAbPowerFixed.pdf'
TSCALE = 20.0 # use this value for e.g. pdfcairo or cairolatex
TITLE = 'MOSFET $I_D$ Vs Time'
YLABEL = 'Drain Current (in \si{\uA})'
XLABEL = 'Time (in \si{\ms})'
set style fill transparent solid 0.5 noborder
set xrange [0:4]
set xtics 0,0.5,4
set mxtics 4
set yrange [-50:450]
set mytics 4
set rmargin 5
LABEL = '\SI{60}{\uA}'
set label 1 LABEL at graph 1.01, first 60
unset key
set samples 1000
set multiplot
set title TITLE
set ylabel YLABEL
set xlabel XLABEL
unset border
set tics scale 0,0.001
set grid mxtics mytics lt -1 lc rgb 'gray90'
plot NaN
unset grid
# keep the current margins for all following plots
set lmargin at screen TSCALE*GPVAL_TERM_XMIN/(1.0*GPVAL_TERM_XSIZE)
set rmargin at screen TSCALE*GPVAL_TERM_XMAX/(1.0*GPVAL_TERM_XSIZE)
set tmargin at screen TSCALE*GPVAL_TERM_YMAX/(1.0*GPVAL_TERM_YSIZE)
set bmargin at screen TSCALE*GPVAL_TERM_YMIN/(1.0*GPVAL_TERM_YSIZE)
# unset almost everything
unset border
unset label
unset xlabel
unset ylabel
set format x ''
set format y ''
unset title
set grid xtics ytics lt -1 lc rgb 'gray70'
plot NaN
unset grid
Id(x) = 347*sin(2*3.14*x) + 60
ID(x) = Id(x) >= 0 ? Id(x) : 0
plot ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
60 w lines lt 2 lw 3 lc rgb 'gray60',\
ID(x) w lines lt 1 lw 5 lc rgb 'navy'
# overdraw borders on left, right, top, bottom
set object 1 rectangle from screen 0, screen 0 to graph 0, screen 1 back \
fillstyle solid noborder
set object 2 rectangle from graph 1, screen 0 to screen 1, screen 1 back \
fillstyle solid noborder
set object 3 rectangle from screen 0, graph 1 to screen 1, screen 1 back \
fillstyle solid noborder
set object 4 rectangle from screen 0, screen 0 to screen 1, graph 0 back \
fillstyle solid noborder
plot NaN
unset object 1
unset object 2
unset object 3
unset object 4
set title TITLE
set ylabel YLABEL
set xlabel XLABEL
set label 1 LABEL at graph 1.01, first 60
set format x
set format y
set tics scale 1,0.5 front
set border
set border lw 2
plot NaN
unset multiplot
set out
It is not possible, to set different layers for all plot elements and stack them arbitrarily. You must play around with set and unset for the various elements.
In order to have the tics drawn only once, I set their scale to 0 (this works for the major tics, but not for the minor tics, where I use 0.001).
I fix the margins after the minor grid lines are drawn (see Gnuplot: Store plot area dimensions for later use).
Unset everything, which shouldn't be drawn again (label, object, arrow, tics labels etc). Do not unset tics, because we want to drawn them last, so just use set format x '' to draw the tics, but not their labels.
Set the tics to their default scale, and set the border before the last plot, to have them drawn above the grid lines and above the plot.
reset
set term tikz size 17cm,10cm dashed standalone header '\usepackage{siunitx}'
set out 'MosfetClassAbPower.tex'
TSCALE = 1.0
# set terminal pdfcairo
# TSCALE = 20.0 # use this value for e.g. pdfcairo or cairolatex
set style fill transparent solid 0.5 noborder
set title 'MOSFET $I_D$ Vs Time'
set ylabel 'Drain Current (in \si{\uA})'
set xlabel 'Time (in \si{\ms})'
set xrange [0:4]
set xtics 0,0.5,4
set mxtics 4
set yrange [-50:450]
set mytics 4
set rmargin 5
set label 1 '\SI{60}{\uA}' at graph 1.01, first 60
unset key
set samples 1000
set multiplot
unset border
set tics scale 0,0.001
set grid mxtics mytics lt -1 lc rgb 'gray90'
plot NaN
unset grid
# keep the current margins for all following plots
set lmargin at screen TSCALE*GPVAL_TERM_XMIN/(1.0*GPVAL_TERM_XSIZE)
set rmargin at screen TSCALE*GPVAL_TERM_XMAX/(1.0*GPVAL_TERM_XSIZE)
set tmargin at screen TSCALE*GPVAL_TERM_YMAX/(1.0*GPVAL_TERM_YSIZE)
set bmargin at screen TSCALE*GPVAL_TERM_YMIN/(1.0*GPVAL_TERM_YSIZE)
# unset almost everything
unset border
unset label
unset xlabel
unset ylabel
set format x ''
set format y ''
unset title
set grid xtics ytics lt -1 lc rgb 'gray70'
plot NaN
unset grid
set tics scale 1,0.5 front
set border
set border lw 2
Id(x) = 347*sin(2*3.14*x) + 60
ID(x) = Id(x) >= 0 ? Id(x) : 0
plot ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
60 w lines lt 2 lw 3 lc rgb 'gray60',\
ID(x) w lines lt 1 lw 5 lc rgb 'navy'
unset multiplot
set out
Result:
Now the ordering is:
minor grid lines
major grid lines
curve
border, tics
Note, that I made some other tiny changes: You can use e.g. graph coordinates to set a label. And some tweaking of the label text.
EDIT:
Cairolatex or epslatex
The proceeding described above works well for any terminal which processes text and graphics together, but not for terminals like cairolatex and epslatex which also in multiplot mode know only two text layer:
front layer, contains all text placed with front keyword.
graphics, contains all graphical elements of all plot commands (also in multiplot mode).
back layer, contains all text placed with back keyword.
This may become a problem, when one wants to cover parts of the graphic (protruding lines) with a white object, but cannot put e.g. the xlabel to the front. Here is an example, which works also with cairolatex:
reset
set terminal cairolatex pdf dashed color standalone header "\\usepackage{siunitx}" size 17cm,10cm
set output 'MosfetClassAbPowerFixed.tex'
TITLE = 'MOSFET $I_D$ Vs Time'
YLABEL = 'Drain Current (in \si{\uA})'
XLABEL = 'Time (in \si{\ms})'
set style fill transparent solid 0.5 noborder
set xrange [0:4]
set xtics 0,0.5,4
set mxtics 4
set yrange [-50:450]
set mytics 4
RMARGIN=0.92
LMARGIN=0.1
set rmargin at screen RMARGIN
set lmargin at screen LMARGIN
set tmargin at screen 0.91
set bmargin at screen 0.11
unset key
set samples 1000
set multiplot
# first plot the minor grid lines
unset border
set tics scale 0,0.001 format ''
set grid mxtics mytics lt -1 lc rgb 'gray90'
plot NaN
# now plot the major grid lines
unset grid
set grid xtics ytics lt -1 lc rgb 'gray70'
plot NaN
unset grid
# plot the actual curve
# overdraw borders on left and right
set object rectangle from graph -0.005, graph 0 to screen LMARGIN, graph 1 front \
fillstyle solid noborder
set object rectangle from screen RMARGIN, graph 0 to graph 1.005, graph 1 front \
fillstyle solid noborder
Id(x) = 347*sin(2*3.14*x) + 60
ID(x) = Id(x) >= 0 ? Id(x) : 0
plot ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
60 w lines lt 2 lw 3 lc rgb 'gray60',\
ID(x) w lines lt 1 lw 5 lc rgb 'navy'
unset object
# plot all tics and labels
LABEL = '\SI{60}{\uA}'
set label 1 LABEL at graph 1.01, first 60 front
set title TITLE
set ylabel YLABEL
set xlabel XLABEL
set tics scale 1,0.5 format
set border
set border lw 2
plot NaN
unset multiplot
set out
Because of the only three layer, I put thin white rectangles between the plot border and the tic labels. To have the objects drawn outside the plotting area, one needs to use at least one coordinate value in screen coordinates, otherwise they are clipped.
As opposed the the first example, I used fixed margins for the whole plot, which I prefer.
This gives:
Related
I am facing a small issue regarding border setting in multiplot. Though I am following a few examples available but still missing top and bottom lines.
here is the code
**
set multiplot
set border lw 2
set origin 0.05,0.49
set size 0.38,0.45
set yrange [-1.5:1.0]
set xrange [0:2.17106]
set ylabel "E-E_F (eV)" offset 0.5 font "Times-Bold, 35"
set ytics 0.5 font "Times-Bold, 35"
unset xlabel
#set title "Cubic" font "Times-Bold,35"
set label "a)" offset -1,12 font "Times-Bold,40"
plot "bands_cs.dat" using 1:($2--.3095296750) w l lc "black" lw 2 notitle, "bands_cs.dat" every :::32::32 u 1:($2--.3095296750) w l lc rgb "blue" lw 3 notitle,"bands_cs.dat" every :::33::33 u 1:($2--.3095296750) w l lc rgb "blue" lw 3 notitle,"bands_cs.dat" every :::34::34 u 1:($2--.3095296750) w l lc rgb "red" lw 3 notitle,"bands_cs.dat" every :::35::35 u 1:($2--.3095296750) w l lc rgb "red" lw 3 notitle
set origin 0.38,0.49
set size 0.14,0.483
unset arrow
unset xtics
unset label
unset yrange
unset xlabel
unset ylabel
#set xrange[0:2000]
set xtics 1000
set yrange[-1.5:1.0]
set border 1+2+4 lt rgb "black"
set title "{/Symbol s}^{AHE}(10^3 Scm^{-1}) " font "Times-Bold,25"
set key opaque box right samplen 0.8 height 1.2
xmn=-50
xmx=2500
set ytics format "" nomirror
set xtics (" " 1000,\
" " 2000 ) font "Times-Bold, 35"
set arrow from xmn, 0.0 to xmx, 0.0 nohead dt "-"
ymn=0.98
ymx=0
set arrow from 2100,-0.2 to 2100,0 nohead dt "-"
unset xlabel
#set xlabel 0,1,2
set xrange [xmn:xmx]
set y2range [0.95:1.02]
set border 8 lt rgb "dark-green" lw 2
set y2tics 0.1 nomirror textcol rgb "dark-green" font "Times-Bold, 30"
plot "cs_yx.dat" u 2:1 w l notitle ' lc rgb'black' lw 4,"strain_yx.dat" u 3:1 w lp axes x1y2 lc rgb "dark-green" lw 4 pt 7 ps 2 notitle
**
In short, i need to change one color side of the plot.
Assuming you just want to have the right y-axis of the 2nd plot in a different color (without y2tics), but the others borders in black. You can simply remove the right border via set border 5 and add a green line via set arrow.
Check help border and help margins and help arrows.
Script:
### set border in different colors
reset session
set multiplot
set margins 0,0,-1,-1 # l, r, b, t
set origin 0.10,0.10
set size 0.60,0.90
set border lw 2
set grid x,y
plot sin(x)
set origin 0.70,0.10
set size 0.20,0.90
unset ytics
set border 5 # only top and bottom
set arrow 1 from graph 1,0 to graph 1,1 lw 2 lc "green" nohead front # "manual" border
set xrange [0:10]
set xtics add ('' 0) # remove 0 label to avoid overlap with 10 of the 1st plot
plot cos(x) lc "green"
unset multiplot
### end of script
Result:
Addition: if you want to have ytics (actually, y2tics) on the right colored axis, you probably have to add a third dummy plot within the multiplot environment. Check the following example:
Script:
### set border in different colors including tics
reset session
set multiplot
set margins 0,0,-1,-1 # l, r, b, t
set origin 0.10,0.10
set size 0.60,0.90
set border lw 2
set grid x,y
plot sin(x)
set origin 0.70,0.10
set size 0.20,0.90
unset ytics
set border 5 # only top and bottom
set xrange [0:10]
set xtics add ('' 0) # remove 0 label to avoid overlap with 10 of the 1st plot
plot cos(x) lc "green"
set border 8 lw 2 lc "green"
set format x ''
set xtics scale 0
set yrange [GPVAL_Y_MIN:GPVAL_Y_MAX] # yrange from previous plot
set y2tics 0.2 nomirror
set link y2 via y inverse y
set format y2 ' '
plot NaN notitle # dummy plot, plots nothing
unset multiplot
### end of script
Result:
Is it possible to add more then one yrange on the left hand side of the plot using gnuplot?
See the figure linked below, please.
Ideally I would need yrange commands such as y3range, y4range, etc.
Using multiplot I could not get what I want.
set multiplot
set lmargin at scr 0.2
set bmargin at scr 0.1 # fix bottom margin
set grid
set y2range [0:20]
plot x, 2*x axes x1y2 # this is your actual plot
unset grid
set lmargin at scr 0.2
set bmargin at scr 0.15 # fix bottom margin
set yrange [0:20] # set yrange to the same as y2 in the first plot
set border 0 # switch off all borders except the left
unset xtics # switch off the stray xtics
plot -1000 notitle # plot something outside of the y(2)range
unset multi
Thank you for your help.
You have to set the yranges accordingly such that the ytics and hence the grid are nicely aligned.
Add an offset to the ytics to tune the distances. Check help xtics.
Code:
### multiple axes
reset session
# common settings for all (sub-)plots
set lmargin at screen 0.15
set bmargin at screen 0.12
set xlabel "my x-title"
set xrange[0:3000]
set grid
set ytics font ",8"
myOffsetY = 0.7
set multiplot
set ylabel "my 1st y-label" tc rgb "red" offset -2,0
set yrange [-10:6]
set ytics -10,2 tc rgb "red" offset 0,0
plot 0.001*x-10 w l lc rgb "red" notitle
set xlabel " "
unset xtics
unset grid
set ylabel "my 2nd y-label" tc rgb "green" offset 2,0
set yrange [-10.0:-2.0]
set ytics -10, 1 tc rgb "green" offset 0,-myOffsetY
set format y "%.1f"
plot 0.002*x -10w l lc rgb "green" notitle
set ylabel "my 3rd y-label" tc rgb "blue" offset -4,0
set yrange [-60:20]
set ytics -60, 10 tc rgb "blue" offset 0,myOffsetY
set format y "%.0f"
plot 0.003*x-10 w l lc rgb "blue" notitle
unset multiplot
### end of code
Result:
I have written a Gnuplot code that plots two figures on one window. I want a total of eight plot to appear in one window. Here a code for two plots in one window given:
#!/usr/bin/gnuplot
reset
set terminal pngcairo size 1000,1000
set output 'spectrogram.png'
set multiplot
unset key
set lmargin at screen 0.1
set rmargin at screen 0.9
set bmargin at screen 0.3
set tmargin at screen 0.9
set label 1 '(a)' font "Times, 15" at 0.8,15 right
set label 2 '(b)' font "Times, 15" at 7.5,90 right
set size ratio 2.5
set style data lines
set xtics format ""
set x2tics nomirror
set ytics out nomirror
set ytics 0,15
set x2label "Vs (km/s)" offset 1
set ylabel 'Depth (km)' offset 1
set xrange [0:5]
set yrange [200:0]
plot 'KUMBHZ.out' lc rgb 'red' lw 2.0 with fsteps,\
'finalmod' lc rgb 'cyan' lw 2.0 with fsteps,\
'modl.out' lc rgb 'navy' lw 2.0 with fsteps,
reset
set size ratio 0.9
set style data points
set xtics 0,10
set border lw 1.5
set ytics 0,0.5
set x2label "Period (s)" offset 1
set ylabel "Group Velocity (km/s)" offset 1
set xrange [10:102]
set yrange [2.5:4.5]
set label 3 at 80,3
set label 3 "C1 (LHMI)" center font "Times, 16"
unset key
set lmargin at screen 0.42
set rmargin at screen 0.8
set bmargin at screen 0.33
set tmargin at screen 0.9
plot 'DSP.out' lc rgb 'red' lw 2.0 with lines,\
'weig' lc rgb 'cyan' lw 2.0 with lines,\
'disp.d' lc rgb 'navy' lw 2.0 with lines,\
'weig.eror' w yerrorbar pt 0 lc black
unset multiplot
I have similar data of total 8 images of which two is shown above. I want 8 images should set on one window.
Did you type help multiplot in gnuplot?
In general, you need more options in multiplot. Start with:
set multiplot layout 2,4 margins 0.04, 0.98, 0.08, 0.98 spacing 0.03,0.02
The layout 2,4 option will give you 2 rows and 4 columns of graphs. Or, you may wish layout 4,2. margins defines margins around all the graphs. spacing defines the space between graphs. I have them pretty small in this example because I pulled this off some work I did where all the graphs had the same axis so I have labels only on the bottom and left charts.
I would like to plot several data colmuns of a datfile in one graph. For each data columnI would like to use a black (differently dashed) line and a coloured point. I found out how to do it in general (by plotting first the line (with lines) and then the points (with points) and afterwards shifting the legend entries on top of each other). This is explained for example in this post:
Merge key entries in gnuplot
But it is not fully working in my case. I have three problems:
First: I would like to have a box around the legend. But this doesnot work when I shift the legend entries on top of each other...
Second: I would like to include a rectangle object. Somehow this always is on top of the plotted lines except the last one...
And the third problem: The xticlabels are plotted for each plot on each other. That is why they seem to be bold which they should not. I found out that I should "hide" the tics (like I do with the border and the labels) but it doesnot work for the tics somehow...
Do you have some hints for me?
Best regards,
Sebastian
#ewcz
#dataset.dat
"\\footnotesize r/R" "\\footnotesize OP1" "\\footnotesize OP2"
0.132 1.018 0.872
0.162 0.940 0.796
0.191 1.014 0.848
0.221 1.043 0.934
0.250 1.010 0.935
0.279 0.987 0.938
0.309 0.962 0.930
0.338 0.929 0.921
0.368 0.897 0.922
0.397 0.876 0.932
0.426 0.831 0.919
0.456 0.795 0.884
#Start terminal
set terminal epslatex size 7.8cm, 6.1cm font ",10"
#Legend settings
pointSize = 1
yticsScale =1
keySpacing = pointSize*yticsScale*1.25
keyY = 15.5
keyX = 0.975
set key vertical Left reverse width -0.5 height +0 font ",16"
set key opaque
set key autotitle columnheader
set key bottom right spacing -1
#Hide border & labels
set border 0
set xlabel " "
set ylabel " "
#Format of axis numbers
set format xy '$\%g$'
set format x '\footnotesize \%10.1f'
set format y '\footnotesize \%10.1f'
#Format tics
set xtics 0,0.1 out nomirror
set xtics offset -0.2,0
set mxtics 5
set ytics 0.6,0.1 out nomirror
set ytics offset 0.4,0
set mytics 5
#Background grid setting
set grid
show grid
set object 1 rectangle from 0.132, graph 0 to 0.456, graph 1 fillcolor rgb "#A9A9A9" fs pattern 1 noborder behind
#Margins
set lmargin 5.9
set rmargin 0.5
set bmargin 3.5
#Axis range settings
set xrange [0:0.535]
set yrange [0.6:1.2]
#Format lines, boxes...
set style line 4 lt 1 lc rgb 'black' lw 2 pt 13 ps 1.25 dt 4
set style line 5 lt 1 lc rgb 'black' lw 2 pt 4 ps 1.0 dt 5
#Multiplot
set multiplot
set origin 0,0
set size 1,1
#Plots
set key at graph keyX, character keyY
plot 'dataset.dat' using 1:2 with lines ls 4, \
'dataset.dat' using 1:2 with points ls 4 lc rgb "#71da71" title " "
#Label settings
set border
set xlabel '\small $r/D_T\;[-]$' offset 0,+0
set ylabel '\small $c_{m2} \cdot A_{T}/Q_T\;[-]$' offset +10.5,+0
#Last Plot
keyY = keyY - keySpacing
set key at graph keyX, character keyY
plot 'dataset.dat' using 1:3 with lines ls 5, \
'dataset.dat' using 1:3 with points ls 5 lc rgb "#4da6ff" title " "
#End of code
unset multiplot
I would propose the following:
Since the keys in both plots are independent, perhaps the most straightforward solution would be to draw the encompassing box manually (see below) by using set object rectangle (although this might need some manual "tweaking" of the size of the box).
The rectangle is on top of the plotted lines since it is duplicated by the second plot. In a sense, this second copy is behind with respect to the second plot, but since this layer is on top of the first plot, it covers the elements plotted by the first plot. One can get rid of this by deleting the object in the context of the second plot with unset object 1.
It is a similar issue with the tics,labels,etc. In the code below, all the definitions are moved before the first plot command and then unset with respect to the second plot.
With these modifications the script would look like:
#Start terminal
set terminal epslatex size 7.8cm, 6.1cm font ",10"
#Legend settings
pointSize = 1
yticsScale =1
keySpacing = pointSize*yticsScale*1.25
keyY = 15.5
keyX = 0.975
set key vertical Left reverse width -0.5 height +0 font ",16"
set key opaque
set key autotitle columnheader
set key bottom right spacing -1
#Format of axis numbers
set format xy '$\%g$'
set format x '\footnotesize \%10.1f'
set format y '\footnotesize \%10.1f'
#Format tics
set xtics 0,0.1 out nomirror
set xtics offset -0.2,0
set mxtics 5
set ytics 0.6,0.1 out nomirror
set ytics offset 0.4,0
set mytics 5
#Background grid setting
set grid
show grid
set object 1 rectangle from 0.132, graph 0 to 0.456, graph 1 fillcolor rgb "#A9A9A9" fs pattern 1 noborder behind
#Margins
set lmargin 5.9
set rmargin 0.5
set bmargin 3.5
#Axis range settings
set xrange [0:0.535]
set yrange [0.6:1.2]
#Format lines, boxes...
set style line 4 lt 1 lc rgb 'black' lw 2 pt 13 ps 1.25 dt 4
set style line 5 lt 1 lc rgb 'black' lw 2 pt 4 ps 1.0 dt 5
#Multiplot
set multiplot
set origin 0,0
set size 1,1
#Plots
set key at graph keyX, character keyY
#simulate key box
set object 2 rectangle from graph keyX, character keyY + 0.5*keySpacing to graph 0.65, character keyY - 1.5*keySpacing fillcolor rgb "#FFFFFF" fs pattern 2 border rgb "black"
set xlabel '\small $r/D_T\;[-]$' offset 0,+0
set ylabel '\small $c_{m2} \cdot A_{T}/Q_T\;[-]$' offset +10.5,+0
plot \
'dataset.dat' using 1:2 with lines ls 4, \
'dataset.dat' using 1:2 with points ls 4 lc rgb "#71da71" title " "
#unset these so that they are not duplicated by the following plot command
unset border
unset xtics
unset ytics
unset xlabel
unset ylabel
unset object 1
unset object 2
#Last Plot
keyY = keyY - keySpacing
set key at graph keyX, character keyY
plot \
'dataset.dat' using 1:3 with lines ls 5, \
'dataset.dat' using 1:3 with points ls 5 lc rgb "#4da6ff" title " "
This then produces (I used standalone epslatex terminal. It might be some font issue, but it seems that the ylabel would benefit from slightly larger horizontal offset):
I've plotted the following in Gnuplot. My issue is that the curves exceed the boundary (so we can see that the purple and blue curves go beyond the y-axis). Any way to solve this problem? I'm hoping there is something that restricts drawing to inside the plotting area. Sure I can just plot less of the curve but that then looks weird. Ideally, I want Gnuplot to go around the frame of the curve and remove any bits of the curve that are there.
I've made the purple curve abnormally fat just to illustrate the problem. The problem is also there with the blue curve though.
The code to produce the above plot is:
#!/usr/bin/env gnuplot
### n: change this parameter to equal the number of data sets to be plotted
n = 2
# t: top margin in pixels
t = 25.0
# b: key height in pixels (bottom margin)
b = 25.0
# h: height of output in pixels
h = 150.0*n + t + b
### define functions to help set top/bottom margins
top(i,n,h,t,b) = 1.0 - (t+(h-t-b)*(i-1)/n)/h
bot(i,n,h,t,b) = 1.0 - (t+(h-t-b)*i/n)/h
### first set up some basic plot parameters
#set term cairolatex size 15cm,15cm
#set output 'DifferentialAmplifierPlot.tex'
set term pdfcairo size 15cm,15cm
set output 'DifferentialAmplifierPlot.pdf'
set border lw 4
set grid mxtics mytics xtics ytics ls '-1' ls '-1' lc rgb 'gray70', lc rgb 'gray90'
set mxtics
set mytics
# Make yrange > ytics > function to get padding.
set yrange [-1.5:1.5]
set ytics ("" -1.5, -1.25 1, -1.0, -0.75 1, -0.5, -0.25 1, 0.0, 0.25 1, 0.5, 0.75 1, 1.0, 1.25 1, "" -1.5)
set xtics 0,1,5
set xrange [0:5]
set xtics
set mxtics
set mytics
set format x ""
set grid xtics ytics mxtics mytics ls -1 ls -1 lc rgb 'gray60', lc rgb '#C0E5E5E5''
set multiplot layout (n+1),1 #font ",14" title 'Input And Output Voltages Of Differential Amplifier'
### First plot
# change only plot command here
currentplot = 1
set tmargin at screen top(currentplot,n,h,t,b)
set bmargin at screen bot(currentplot,n,h,t,b)
unset key
unset xlabel
set title 'Input (Bottom) And Output (Top) Voltages Of The Differential Amplifier'
set ylabel 'Voltage [V]'
plot 'DifferentialAmplfier.dat' using (1000*$1):2 with lines lw 20 lc rgb 'dark-magenta'
### Last plot
# change only plot command here
currentplot = currentplot + 1
set tmargin at screen top(currentplot,n,h,t,b)
set bmargin at screen bot(currentplot,n,h,t,b)
set format x
unset title
set xlabel 'Time [ms]'
set ylabel 'Voltage [mV]'
plot 'DifferentialAmplfier.dat' using (1000*$1):(1000*$3) with lines lw 10 lc rgb 'navy'
unset multiplot
set term x11
Questionable/Dodgy fix...
There is a way to do this but it is cumbersome. You would use a multiplot, plot your data, then through judicious use of the graph and screen coordinate systems plot white rectangles around your plot, then replot an empty plot to redraw the borders (because the rectangles will have overwritten your labels and half of the border line thickness). Here is an MWE:
#!/usr/bin/gnuplot -persist
reset
f(x) = sin(x)
xl=0; xh=20; yl=-1; yh=1;
set xrange [xl:xh]
set yrange [yl:yh]
set multiplot
plot f(x) not w l lt 3 lw 12
## overdraw borders on left, right, top, bottom
set object 1 rectangle from screen 0, screen 0 to graph 0, screen 1 behind \
fillstyle solid noborder
set object 2 rectangle from graph 1, screen 0 to screen 1, screen 1 behind \
fillstyle solid noborder
set object 3 rectangle from screen 0, graph 1 to screen 1, screen 1 behind \
fillstyle solid noborder
set object 4 rectangle from screen 0, screen 0 to screen 1, graph 0 behind \
fillstyle solid noborder
plot NaN not
unset multiplot