gnuplotinsets

Gnuplot: inset from file .plt


I have 2 generic Gnuplot files: plot1.plt and plot2.plt already saved. I need to merge them in a single plot in which plot2.plt is an inset of plot1.plt.

I think I can explain better with a picture. The final result, let's say, should be something like that

Plot2.plt as an inset of plot1.plt

In this image plot2.plt is the inset and the main plot is plot1.plt. Each file can be loaded in Gnuplot correctly and independently.

Thank you for any advice.

Edit: The code is (but it's not working correctly) something like this:

set multiplot

load "plot1.plt"           # plot main figure

set size 0.6, 0.5       # set size of inset
set origin 0.4, 0.5     # move bottom left corner of inset
load "plot2.plt"             # plot inset

unset multiplot

plot1.plt and plot2.plt are generic plot files. To not make it more complicate you can generate them in this way:

plot sin(x)
save "plot1.plt"     #or choose your folder
plot exp(x)
save "plot2.plt"     #or choose your folder

The above code yields:

What I get from the code above

Setting different size or origin for the inset, unfortunately, does not affect the result. I'm using GNUPLOT version 5.0 patchlevel 4. I'm sorry for my bad English, I'm not a native speaker. Please feel free to fix grammar/spelling.

EDIT 2: I now provide the code for the file plot1.plt. Please feel free to edit and remove (entirely or partially) it if you think it's too long.

#!/gnuplot
#
#    
#       G N U P L O T
#       Version 5.0 patchlevel 4    last modified 2016-07-21 
#    
#       Copyright (C) 1986-1993, 1998, 2004, 2007-2016
#       Thomas Williams, Colin Kelley and many others
#    
#       gnuplot home:     http://www.gnuplot.info
#       faq, bugs, etc:   type "help FAQ"
#       immediate help:   type "help"  (plot window: hit 'h')
# set terminal wxt 0 enhanced
# set output
unset clip points
set clip one
unset clip two
set bar 1.000000 front
set border 31 front lt black linewidth 1.000 dashtype solid
set zdata 
set ydata 
set xdata 
set y2data 
set x2data 
set boxwidth
set style fill  empty border
set style rectangle back fc  bgnd fillstyle   solid 1.00 border lt -1
set style circle radius graph 0.02, first 0.00000, 0.00000 
set style ellipse size graph 0.05, 0.03, first 0.00000 angle 0 units xy
set dummy x, y
set format x "% h" 
set format y "% h" 
set format x2 "% h" 
set format y2 "% h" 
set format z "% h" 
set format cb "% h" 
set format r "% h" 
set timefmt "%d/%m/%y,%H:%M"
set angles radians
set tics back
unset grid
set raxis
set style parallel front  lt black linewidth 2.000 dashtype solid
set key title "" center
set key inside right top vertical Right noreverse enhanced autotitle nobox
set key noinvert samplen 4 spacing 1 width 0 height 0 
set key maxcolumns 0 maxrows 0
set key noopaque
unset label
unset arrow
set style increment default
unset style line
unset style arrow
set style histogram clustered gap 2 title textcolor lt -1
unset object
set style textbox transparent margins  1.0,  1.0 border
unset logscale
set offsets 0, 0, 0, 0
set pointsize 1
set pointintervalbox 1
set encoding default
unset polar
unset parametric
unset decimalsign
set view 60, 30, 1, 1
set samples 100, 100
set isosamples 10, 10
set surface 
unset contour
set cntrlabel  format '%8.3g' font '' start 5 interval 20
set mapping cartesian
set datafile separator whitespace
unset hidden3d
set cntrparam order 4
set cntrparam linear
set cntrparam levels auto 5
set cntrparam points 5
set size ratio 0 1,1
set origin 0,0
set style data points
set style function lines
unset xzeroaxis
unset yzeroaxis
unset zzeroaxis
unset x2zeroaxis
unset y2zeroaxis
set xyplane relative 0.5
set tics scale  1, 0.5, 1, 1, 1
set mxtics default
set mytics default
set mztics default
set mx2tics default
set my2tics default
set mcbtics default
set mrtics default
set xtics border in scale 1,0.5 mirror norotate  autojustify
set xtics  norangelimit autofreq 
set ytics border in scale 1,0.5 mirror norotate  autojustify
set ytics  norangelimit autofreq 
set ztics border in scale 1,0.5 nomirror norotate  autojustify
set ztics  norangelimit autofreq 
unset x2tics
unset y2tics
set cbtics border in scale 1,0.5 mirror norotate  autojustify
set cbtics  norangelimit autofreq 
set rtics axis in scale 1,0.5 nomirror norotate  autojustify
set rtics  norangelimit autofreq 
unset paxis 1 tics
unset paxis 2 tics
unset paxis 3 tics
unset paxis 4 tics
unset paxis 5 tics
unset paxis 6 tics
unset paxis 7 tics
set title "" 
set title  font "" norotate
set timestamp bottom 
set timestamp "" 
set timestamp  font "" norotate
set rrange [ * : * ] noreverse nowriteback
set trange [ * : * ] noreverse nowriteback
set urange [ * : * ] noreverse nowriteback
set vrange [ * : * ] noreverse nowriteback
set xlabel "" 
set xlabel  font "" textcolor lt -1 norotate
set x2label "" 
set x2label  font "" textcolor lt -1 norotate
set xrange [ * : * ] noreverse nowriteback
set x2range [ * : * ] noreverse nowriteback
set ylabel "" 
set ylabel  font "" textcolor lt -1 rotate by -270
set y2label "" 
set y2label  font "" textcolor lt -1 rotate by -270
set yrange [ * : * ] noreverse nowriteback
set y2range [ * : * ] noreverse nowriteback
set zlabel "" 
set zlabel  font "" textcolor lt -1 norotate
set zrange [ * : * ] noreverse nowriteback
set cblabel "" 
set cblabel  font "" textcolor lt -1 rotate by -270
set cbrange [ * : * ] noreverse nowriteback
set paxis 1 range [ * : * ] noreverse nowriteback
set paxis 2 range [ * : * ] noreverse nowriteback
set paxis 3 range [ * : * ] noreverse nowriteback
set paxis 4 range [ * : * ] noreverse nowriteback
set paxis 5 range [ * : * ] noreverse nowriteback
set paxis 6 range [ * : * ] noreverse nowriteback
set paxis 7 range [ * : * ] noreverse nowriteback
set zero 1e-008
set lmargin  -1
set bmargin  -1
set rmargin  -1
set tmargin  -1
set locale "Italian_Italy.1252"
set pm3d explicit at s
set pm3d scansautomatic
set pm3d interpolate 1,1 flush begin noftriangles noborder corners2color mean
set palette positive nops_allcF maxcolors 0 gamma 1.5 color model RGB 
set palette rgbformulae 7, 5, 15
set colorbox default
set colorbox vertical origin screen 0.9, 0.2, 0 size screen 0.05, 0.6, 0 front bdefault
set style boxplot candles range  1.50 outliers pt 7 separation 1 labels auto unsorted
set loadpath 
set fontpath 
set psdir
set fit brief errorvariables nocovariancevariables errorscaling prescale nowrap v5
GNUTERM = "wxt"
plot sin(x)
#    EOF

Solution

  • Ok,

    I found the answer my myself, so I'm going to share my findings.

    As in the question, let plot2.plt be an inset of plot1.plt. Opening plot2.plt with any text editor we can see the code behind the plot. We have to search these two specific lines:

    set size ratio 0 1,1
    set origin 0,0
    

    since plot2.plt, in my example, is loaded after the commands set size and set origin,

    set multiplot
    
    load "plot1.plt"           # plot main figure
    
    set size 0.6, 0.5       # set size of inset
    set origin 0.4, 0.5     # move bottom left corner of inset
    load "plot2.plt"             # plot inset
    
    unset multiplot
    

    they overwrite the expected correct size and ratio. To fix that I ended editing the plot2.plt in this way:

    set size ratio 0 0.6,0.5    #old line: set size ratio 0 1,1
    set origin 0.4,0.5          #old line: set origin 0,0
    

    Let's say we save the modified file as plot2_mod.plt. Now, to get the correct inset we can write:

    set multiplot
    load "plot1.plt"           # plot main figure
    load "plot2_mod.plt"       # plot inset
    unset multiplot
    

    and the result is:

    Plot with the desired inset

    Obviously there's still some work to do, but this answer the main point of the question: how to plot an inset using already saved .plt files.

    I'm sorry for my bad English, I'm not a native speaker. Please feel free to fix grammar/spelling.

    Thank you all for your help and suggestions.