Gnuplot Multiplot Individual Plot Sizes + Labels - gnuplot

I am currently trying to produce a decent multiplot in Gnuplot. Sadly I ran into some problems.
As the y-axis for both figures is the same I want to only label and tic it once, however I cant remove those from only the left plot.
Secondly I want to increase the width of the left plot while decreasing the one of the right.
Here is a picture of what I got so far, the code is below.
Plot so far
set term postscript eps enhanced color "Helvetica" 10
set output "dosband.eps"
set title "Bandstructure and Density of States"
#
set multiplot layout 1,2 \
margins 0.075,0.98,0.1,0.98 \
spacing 0.02,0.08 #margins: left,right,bottom,top; spacing: vertical, horizontal
set title "Bandstructure"
plot 'plotband.dat' using 1:2 with lines lt 1 lw 0.5 linecolor rgb "black" notitle
set xlabel "Density [states/eV]" #dont ask me why I have to swap the xlabels around
set ylabel "Energy [eV]"
#
set title "Density of States"
plot 'plotdos.dat' using 1:2 with lines lt 1 linecolor rgb "black" notitle
set xlabel "K-Points"
unset multiplot
Thanks in advance for any answers!

As noted by #Christoph, using explicit margins is one of the solutions. In your particular case, you could proceed as:
#dimensions are in screen units
width_left = 0.48
width_right = 0.25
eps_v = 0.12
eps_h_left = 0.1
eps_h_right = 0.05
unset key
set multiplot
set tmargin at screen 1. - eps_v
set bmargin at screen eps_v
set lmargin at screen 0.1
set rmargin at screen eps_h_left + width_left
set xr [0:1.4]
set xtics 0,0.2,1.4
set yr [-40:5]
unset ytics
set y2r [-40:5]
set y2tics in mirror
set format y2 "" #draw ticks but no tic labels
set title "Plot 1"
set xlabel "title 1"
plot 1/0
set lmargin at screen 1. - (width_right + eps_h_right)
set rmargin at screen 1. - eps_h_right
set xr [0:100]
set xtics 0,25,100
unset y2tics
set yr [-40:5]
set ytics in mirror
set mytics 1
set title "Plot 2"
set xlabel "title 2"
set ylabel "Energy [eV]"
plot 1/0
This produces:
In case the Energy [eV] label is supposed to be moved completely to the left, one can adjust the spacings/tics accordingly...

Related

Adding more than one yrange on the left hand side of the plot using gnuplot

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:

Four graphs in one picture

What is wrong please with this graph? I would like to plot four graph in one picture. It displays two graphs. I would like to have one legends with 3 titles, because there are three color used. Then I don't know how to write two titles - one for graphs in left and one for graphs in right.
I would like to have 4 differents plot 2x2 - I have 4 plot in script. I there is lots of mistake.
set tics out nomirror
set encoding iso_8859_1
unset xtics
set ylabel "{/:Italic F} [a. u.]" font "Segoe UI,12" offset 2,0
set ytics nomirror font "Segoe UI,12"
set lmargin screen 0.2 #levý prostor vedle graf
set rmargin screen 0.9 #pravý prostor vedle grafu
set multiplot layout 2,2
set bmargin screen 0.40
set key Left reverse out horiz
set format y "%.2f"
set key tc variable
set xrange [4272:4500]
set yrange [0.7:1.02]
set title "Title 1" font "Segoe UI,12"
set title "Title 2" font "Segoe UI,12"
plot \
x title "Fitted" with lines linecolor rgb "red" lw 1.5,\
x title "Measured" with lines linecolor rgb "black" lw 1.5
unset ytics
set y2tics
set link y2
unset ylabel
set y2label "{/:Italic F} [a. u.]" font "Segoe UI,12" offset 1,0
set tmargin screen 0.4 #posun horní čáry dolního graf
set bmargin screen 0.15 #posun dolní čáry dolního graf
unset key
set tics out nomirror
set xlabel "{/:Italic {/Symbol l}} ({\305})" font "Segoe UI,12"
set xrange [4272:4500]
set yrange [-0.05:0.03]
plot x title "Measured - fitted" with lines linecolor rgb "navy" lw 1.5
set margin
set margin
plot \
x title "Fitted" with lines linecolor rgb "red" lw 1.5,\
x title "Measured" with lines linecolor rgb "black" lw 1.5
set margin
set margin
plot x title "Measured - fitted" with lines linecolor rgb "navy" lw 1.5
I suggest you have a look at plots in the gnuplot online demo collection, in particular this one: custom_key.dem
That demo illustrates automatic placement of separate plots into a grid via the set multiplot layout command, and also illustrates construction of a single legend holding titles and information from the constituent plots. The online copy includes a copy of the commands that generated the plot. If you have trouble adapting that example to your own data, come back and show what you have tried so that people can make further suggestions.
I could see that you used some symbols from symbol font.
If you want, use set encoding utf8 option and write symbols is directly.
You could set font as a terminal option also.
For example: set terminal pngcairo size 800,600 font "Segoe UI,8" enhanced.
To help you to understand as margins screen works, take a look on this figure.
This grid divides the screen (size 800,600 on terminal command) each 10% (0.1 screen unit).
In order to have graphs with the same size and align them each other we have to set the margins of the individual graphs manually.
To make it more easy I used macros commands.
Below a complete example of how to create a 2×2 graph using the multiplot.
reset
set encoding utf8 # Encoding
set terminal pngcairo size 800,600 font "Segoe UI,8" enhanced # Terminal settings
set output "multiplot_2x2.png" # Output file name
set grid ls -1 lc "gray" # grid lines
set tics out nomirror # tics marks
# Line styles
set style line 1 lc "#e41a1c" # red
set style line 2 lc "#377eb8" # blue
set style line 3 lc "#4daf4a" # green
set style line 4 lc "#984ea3" # purple
# Margins for each row and column
Row1 = "set tmargin screen 0.90; set bmargin screen 0.56" # Top and bottom margins
Row2 = "set tmargin screen 0.42; set bmargin screen 0.08"
Col1 = "set lmargin screen 0.08; set rmargin screen 0.48" # Left and right margins
Col2 = "set lmargin screen 0.57; set rmargin screen 0.97"
# Multiplot option with main title
set multiplot layout 2,2 rowsfirst title "{/:Bold=12 Multiplot 2×2}"
# -------------------------------------------------------------------
#Row1; #Col1 # Calling the macros
set title "{/:Bold=10 Row 1, Col 1}" # Title for plot
set xrange [-10:10] # x-range
set yrange [0:50] # y-range
set xtics 2 # Increment for x-tics
set ytics 10 # Increment for y-tics
set xlabel "Crazy distance / Å" # x-label
set ylabel "Crazy values / a.u." # y-label
plot x**2 w l ls 1 title "x^{2}" # The plot
# -------------------------------------------------------------------
#Row1; #Col2
set title "{/:Bold=10 Row 1, Col 2}"
set xrange [-15:20]
set yrange [-4000:8000]
set xtics 5
set ytics 2000
set xlabel "Crazy temperature / °C"
set ylabel "Crazy pressure / Pa"
plot x**3 w l ls 2 title "x^{3}"
# -------------------------------------------------------------------
#Row2; #Col1
set title "{/:Bold=10 Row 2, Col 1}"
set xrange [-15:15]
set yrange [-0.4:1.2]
set xtics 5
set ytics 0.2
set xlabel "Crazy energy / kJ"
set ylabel "Crazy volume / m^{3}"
plot sin(x)/x w l ls 3
# -------------------------------------------------------------------
#Row2; #Col2
set title "{/:Bold=10 Row 2, Col 2}"
set xrange [0:14]
set yrange [-10:15]
set xtics 2
set ytics 5
set xlabel "Crazy value {/:Italic N}_{A} / 10^{23}"
set ylabel "Crazy property / cd sr kg^{−1} m^{−2} s^{3}"
plot cos(x)*x w l ls 4
# -------------------------------------------------------------------
unset multiplot
The result:
Exactly the same result can be achieved using approach on #Ethan's answer, with the advantage dismiss macros use, just write:
set multiplot \
layout 2,2 rowsfirst \
title "{/:Bold=12 Multiplot 2×2}" \
margins screen 0.08,0.97,0.08,0.90 \
spacing screen 0.09,0.14

In GNUPLOT mutliplot option, the label for X-axis is not plotted for second plot

I have two plots in multiplot, on my second plot ticks label is not appearing, which I want to appear at the bottom X-axis
#!/usr/bin/gnuplot
reset
set border lw 30
set term pngcairo size 10000,10000 font "arial-Bold,130"
set output 'out.png'
set multiplot layout 2,2
unset key
set size ratio 1.2
set style data lines
set xtics format ""
set x2tics nomirror
set ytics out nomirror
set ytics 0,20
set x2label "Vs (km/s)" offset -1.0
set ylabel 'Depth (km)' offset 1.5
set xrange [0:5]
set yrange [200:0]
set label 3 at 2,120
set key samplen 1.7 at 3.0,135
#
set label 1 '(a)' font "arial-Bold,130" at 0.8,15 right
set label 3 "C3 (MNAI)" center font "arial-Bold,130"
plot 'MAN.inmd' lc rgb 'blue' lw 35 title "Initial model" with fsteps,\
'MAN.outmd' lc rgb 'red' lw 35 dt"-" title "Inverted model" with fsteps ,
unset x2label
unset x2tics
unset ylabel
unset ytics
#
set size ratio 0.9
set xlabel
set xtics 5
set ytics 0.5
set xlabel "Period (s)" offset 2.5
set ylabel "Group Velocity (km/s)" offset 2.5
set xrange [15:45]
set yrange [3:4.5]
set label 3 at 30,3.5
set label 4 at 18,4.3
set label 5 at 20,4.0 font "arial-Bold,130"
set key right bottom samplen 0.9
#
set label 3 "C1 (MNAI)" center font "arial-Bold,130"
set label 5 "Rayleigh wave dispersion curves" font "arial-Bold,130"
set label 4 "(a)" center font "arial-Bold,97"
plot 'MANdsp.out' lc rgb 'red' lw 35 title "Model fit dispersion curve",\
'mandsp.in' lc rgb 'blue' lw 35 dt"-" title "Observed dispersion curve" smooth acsplines,
unset multiplot
The ticks are appearing on X-axis, but the ticks X-axis bottom labels are not appearing. I have tried other ways too, but unable to come over it
Regarding xtics, you do the following:
...
set xtics format "" # Don't print x-axis bottom tic labels!!!
...
set x2tics nomirror # Print x2tics, tic labels are included by default.
...
...# First plot # -> You see x2 tic labels.
...
unset x2tics # Don't print x2 tics
...
set xtics 5 # Print x-axis tics, but keep empty tic labels.
...
...# Second plot # -> no x2 tics; xtics are printed without labels.
You can reset the x-axis tic label default format with:
set xtics 5 format "% h"
See help set format for other format options.
So if I take your script and change it with the following steps
replace the two plot commands with plot sin(x), cos(x) because you did not show the data,
replace the set xtics 5 command by set xtics 5 format "% h",
I arrive at this script:
#!/usr/bin/gnuplot
reset
set border lw 30
set term pngcairo size 10000,10000 font "arial-Bold,130"
set output 'out.png'
set multiplot layout 2,2
unset key
set size ratio 1.2
set style data lines
set xtics format ""
set x2tics nomirror
set ytics out nomirror
set ytics 0,20
set x2label "Vs (km/s)" offset -1.0
set ylabel 'Depth (km)' offset 1.5
set xrange [0:5]
set yrange [200:0]
set label 3 at 2,120
set key samplen 1.7 at 3.0,135
#
set label 1 '(a)' font "arial-Bold,130" at 0.8,15 right
set label 3 "C3 (MNAI)" center font "arial-Bold,130"
#plot 'MAN.inmd' lc rgb 'blue' lw 35 title "Initial model" with fsteps,\
#'MAN.outmd' lc rgb 'red' lw 35 dt"-" title "Inverted model" with fsteps ,
plot sin(x), cos(x)
unset x2label
unset x2tics
unset ylabel
unset ytics
#
set size ratio 0.9
set xlabel
set xtics 5 format "% h"
set ytics 0.5
set xlabel "Period (s)" offset 2.5
set ylabel "Group Velocity (km/s)" offset 2.5
set xrange [15:45]
set yrange [3:4.5]
set label 3 at 30,3.5
set label 4 at 18,4.3
set label 5 at 20,4.0 font "arial-Bold,130"
set key right bottom samplen 0.9
#
set label 3 "C1 (MNAI)" center font "arial-Bold,130"
set label 5 "Rayleigh wave dispersion curves" font "arial-Bold,130"
set label 4 "(a)" center font "arial-Bold,97"
#plot 'MANdsp.out' lc rgb 'red' lw 35 title "Model fit dispersion curve",\
#'mandsp.in' lc rgb 'blue' lw 35 dt"-" title "Observed dispersion curve" smooth acsplines,
plot sin(x), cos(x)
unset multiplot
And I get this picture with x axis tic labels on the right diagram:

multiplot - stacking 3 graphs on a larger canvas

I have been trying very unsuccessfully to stack 3 graphs together in a multi-plot layout on a canvas that is a ratio of 2:3(width by height).
set terminal postscript eps enhanced "Helvetica" 24 color
set output "data.eps"
set timefmt "%s"
#set size 1.0,1.5
#set bmargin 2
#set tmargin 2
set size 1.0,1.5
set multiplot layout 3,1
set size 1.0,0.5
set tmargin 2
set bmargin 0
set ylabel 'Distance'
set format x ""
set ytics nomirror font "Helvetica,10"
set key top
plot "trace1.dat" using 1:3 axes x1y1 title "distances" with lines lw 2 lc rgb 'blue'
set size 1.0,0.5
set bmargin 0
set tmargin 0
set ylabel 'Power (W)'
set format x ""
set ytics nomirror font "Helvetica,10"
set key top
plot "trace2.dat" using 1:2 axes x1y1 title "device" with lines lw 2 lc rgb 'red'
set size 1.0,0.5
set bmargin
set tmargin 0
set xdata time
set ylabel 'Power (W)'
set xlabel 'Time (EST)' offset 0,-2.8 font "Helvetica,32
set format x "%b %d, %H:%M"
set ytics nomirror font "Helvetica,10"
set xtics nomirror rotate by 90 offset 0,-2.0 out font "Helvetica,10"
set key top
plot "trace3.dat" using 1:2 axes x1y1 title "aggr" with lines lw 2 lc rgb 'blue'
unset multiplot
When I do something like above, I get the plot shown below, there's a lot of blank space at the top of the canvas and the 3 multiplot graphs seem to overlap each other.
Any kind of help or pointer will be greatly appreciated.
In order to use a bigger canvas, you must use the size option when setting the terminal, e.g.:
set terminal postscript eps enhanced size 10cm,15cm
set size just changes the plot size relative to your canvas. To see this, consider
set terminal wxt
set size 1.0,1.5
plot sin(x)
Parts of the plot disappear, because it is much too high with respect to the canvas.
To stack three plots with same heights, in my opinion its best to use fixed margins:
set terminal pngcairo size 600, 900
set output 'stacking.png'
set lmargin at screen 0.15
set rmargin at screen 0.95
TOP=0.98
DY = 0.29
set multiplot
set offset 0,0,graph 0.05, graph 0.05
set xlabel 'time'
set ylabel 'ylabel 1' offset 1
set tmargin at screen TOP-2*DY
set bmargin at screen TOP-3*DY
set ytics -1000,500,1000
plot 1150*cos(x) title 'First'
set xtics format ''
unset xlabel
set ylabel 'ylabel 2' offset 0
set tmargin at screen TOP-DY
set bmargin at screen TOP-2*DY
set ytics -100,50,100
plot 101*sin(x) title 'Second'
set ylabel 'ylabel 3' offset -1
set tmargin at screen TOP
set bmargin at screen TOP-DY
set ytics -8,4,8
plot 10*sin(2*x) title 'Third'
unset multiplot; set output
The result is (with 4.6.3):
In order to avoid overlapping labels of the ytics, you must change the range where the tics are drawn, e.g. with set ytics -100,50,100, which puts ytics between -100 and 100 in steps of 50. Using set ytics rangelimited doesn't work
To increase the distance between the plot curve and the border, use set offset with graph coordinates, like done in the above script.
I started with the lowest plot, because only that has x labels and an xlabel.
You need to use set origin, too.
set terminal postscript eps enhanced
set output "data.eps"
set size 1.0,1.5
set multiplot layout 3,1
set size 1.0,0.5
set origin 0,1
...
plot ...
set size 1.0,0.5
set origin 0,0.5
...
plot ...
set size 1.0,0.5
set origin 0,0
...
plot ...
unset multiplot

Gnuplot: Multiplot Plot Just Curve Without Axis Or Title etc

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:

Resources