Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiplot - stacking 3 graphs on a larger canvas

Tags:

gnuplot

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.

plt

Any kind of help or pointer will be greatly appreciated.

like image 269
Sandman Avatar asked Oct 02 '13 06:10

Sandman


1 Answers

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):

enter image description here

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.

like image 66
Christoph Avatar answered Oct 26 '22 15:10

Christoph