Gnuplot: multiplot and insets

Viewed 516

I have two plots, say

set multiplot # First plot with inset
plot exp(-x)            
set size 0.6, 0.5     
set origin 0.4, 0.5 
plot cos(x)  
unset multiplot

set multiplot # Second plot with inset
plot exp(-2x)            
set size 0.6, 0.5     
set origin 0.4, 0.5 
plot sin(x)  
unset multiplot

This will create two separate plots, but I really would like a single output with both plots next to each other. As a pseudo-code, I would expect something like

 set multiplot layout 1,2
    set multiplot
    plots+insets of first plot here
    unset multiplot
    set multiplot
    plots+insets of second plot here
    unset multiplot
 unset multiplot

Of course, I dont think you can (easily) nest multiplot like that, so maybe a different approach is necessary? To re-phrase the question: how does one use multiplot to create different plots next to each other so that some of these plots also contain insets (which itself requires the use of multiplot)?

EDIT: as a response to Ethan's comment: The final output is only intended to be a pdf image. I am ok to first create the individual plots and afterwards put them together, however I would like to still be able to position the two images relative to each other. In particular, it should be possible to "fuse" the right border of the first image and the left border of the second image. Within a single multiplot, this can for example be done by modifying the tmargins and bmargins. Can this still be done with separate images?

2 Answers

This is how I understand your question. I guess you simply need to set the origin and sizes yourself. You can use variables to calculate the necessary values.

Code:

### multiplot with "insets"
reset session

set key top left
set multiplot 

    # settings for main plots
    set ytics auto

    # first plot
    s1x = 0.5
    s1y = 1.0
    set size s1x, s1y
    o1x = 0.0
    o1y = 0.0
    set origin o1x, o1y
    plot exp(-x)
    
    # second plot
    s2x = 0.5
    s2y = 1.0
    set size s2x, s2y
    o2x = 0.5
    o2y = 0.0
    set origin o2x, o2y
    set ytics auto
    plot exp(-2*x)       
    
    # settings for insets
    set ytics 0.5
    
    # first inset
    set size   s1x*0.6, s1y*0.5     
    set origin o1x+s1x*0.4, o1y+s1y*0.5 
    plot cos(x)  

    # second inset
    set size s2x*0.6, s2y*0.5     
    set origin o2x+s2x*0.4, o2y+s2y*0.5 
    plot sin(x)  

unset multiplot
### end of code

Result:

enter image description here

You only need a single multiplot environment. You can simulate nested multiplots by manually placing each plot on the desired position on the page, for example something like this:

set nokey

set multiplot

set size 0.5, 1
set origin 0, 0
plot exp(-x)            

set size 0.3, 0.5     
set origin 0.2, 0.5 
plot cos(x)  

set size 0.5, 1
set origin 0.5, 0
plot exp(-2*x)           

set size 0.3, 0.5     
set origin 0.7, 0.5 
plot sin(x)  

unset multiplot

Result:

simulated multiplots with inset

Related