3

I try to create a combination of multiplots (2x2) and a single plot. I am not sure what I am making wrong but I can't figure out how to do it. My attempt:

plot sin(x) title "this should be a single plot"

set multiplot layout 2,2 title "Those are the multiplots"

set title "A!"
plot sin(x)

set title "B!"
plot cos(x) not

set title "C!"
tan(x) title "tan"

set title "D"
tan(0.5*x) not

No matter if I put plot after or earlier but I can't visualize it.

Thanks.

1 Answer 1

5

you should add a plot command before the last two functions and maybe a unset multiplot at the end. This should work. Or do you want the single plot and the multiplot both visible?

plot sin(x) title "this should be a single plot"

set multiplot layout 2,2 title "Those are the multiplots"

set title "A!"
plot sin(x)

set title "B!"
plot cos(x) not

set title "C!"
plot tan(x) title "tan"

set title "D"
plot tan(0.5*x) not

unset multiplot

Edit: (manual setting of sizes, origins and margins)

### Multiplot layout
reset session
set multiplot title "These are five plots"
set ytics 0.5

set margins 5,5,2,8 # l,r,b,t

set size 1,0.5
set origin 0,0.6
set title "top plot"
plot sin(x) title "this should be a single plot"

set size 0.5,0.5

set origin 0,0.3
set title "A!"
plot sin(x)

set origin 0.5,0.3
set title "B!"
plot cos(x)

set origin 0,0
set title "C!"
plot sin(2*x)

set origin 0.5,0
set title "D"
plot cos(2*x)

unset multiplot
### end of code

Result:

enter image description here

Addition:

Just for fun, maybe it is useful to you or somebody else. With a few lines you'll have an easy way to set your layout within a matrix with a few numbers stored in $Layout. I hope it is self-explaining.

Code: (edit: simplified)

### easy configurable multiplot layout
reset session

# row column height width
$Layout <<EOD
1 1 1 1
1 2 2 2
1 4 2 1
2 1 1 1
3 1 1 4
EOD

stats $Layout u ($1+$3):($2+$4) nooutput  # get max number of rows and columns
MPRows       = STATS_max_x - 1
MPCols       = STATS_max_y - 1
r(i)         = word($Layout[i],1)
c(i)         = word($Layout[i],2)
h(i)         = word($Layout[i],3)
w(i)         = word($Layout[i],4)
MPGridX      = 1.0/MPCols
MPGridY      = 1.0/MPRows
MPSizeX(i)   = MPGridX*w(i)
MPSizeY(i)   = MPGridY*h(i)
MPOriginX(i) = MPGridX*(c(i)-1)
MPOriginY(i) = 1-MPGridY*(r(i)+h(i)-1)

SetLayout = 'i=i+1; \
             set origin MPOriginX(i), MPOriginY(i); \
             set size   MPSizeX(i)  , MPSizeY(i)'
 
set multiplot
    set linetype 1 lc rgb "red"
    i=0
    @SetLayout
    plot sin(x)
 
    @SetLayout
    plot cos(x)
 
    @SetLayout
    plot x**3
   
    @SetLayout
    plot x**2
   
    @SetLayout
    plot sin(x)/x
unset multiplot
### end of code

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

I would like to have both the plot and multiplots visible. Something like: -a wide (2 column) plot -2x2 grid of plots
In this "special" case, I guess you have to set the sizes, origins and margins manually. I will add an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.