Gnuplot: inset from file .plt - gnuplot

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

OK, here a generic answer, extracted from Philipp K. Janert "Gnuplot in Action".
# functions to be plotted
f(x,a) = x<a ? sqrt(a-x) : 0 # Magnetization
g(x,b) = 0.25*x**4 + b*x**2 # Free Energy
# does the magic:
set multiplot
# the full graph
set grid
plot [-3:2.5][-1:2] f(x,0) notitle w l lw 3
# formatting the inset graphs
unset grid
unset tics
unset xtics
unset ytics
unset key
set tmargin 0; set bmargin 0; set rmargin 0; set lmargin 0
set size 0.2 # relative size of the insets
# draw three insets, clear background, at given origins
set origin 0.175,0.425
clear
plot [-2.5:2.5][-1.5:2] g(x,-1)
set origin 0.4625,0.125
clear
plot [-2.5:2.5][-0.5:3] g(x,0)
set origin 0.675,0.425
clear
plot [-2.5:2.5][-0.5:3] g(x,1)
# cleanup
unset multiplot
which yields
Without your code, have to stop right here but this should get you going.

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.

Related

Plot Complex function in Gnuplot

I have the following code for gnuplot:
set encoding utf8
set zlabel 'Im(z)'
set ylabel 'Re(z)'
unset key
set view map scale 1.2
set isosamples 500, 500
set samples 500
set size ratio 1 1,1
set style data lines
set title "Phase angle"
set cblabel "Angulo de fase"
set cblabel offset character -2, 0, 0 font "" textcolor lt -1 rotate by -270
set cbrange [ -pi : pi ] noreverse nowriteback
set cbtics ("0" -pi, "2π" pi)
set palette defined ( 0 0 1 1, 1 1 1 1 )
set xrange [-6:6] noreverse nowriteback
set yrange [-6:6] noreverse nowriteback
set palette positive nops_allcF maxcolors 0 gamma 1.5 color model HSV
Hue(x,y) = (pi + atan2(y,x)) / (2*pi)
phase(x,y) = hsv2rgb( Hue(x,y), sqrt(x**2+y**2) )
f(x,y) = 1/((x+y*{0,1})-7)
rp(x,y) = real(f(x,y))
ip(x,y) = imag(f(x,y))
color(x,y) = hsv2rgb( Hue( rp(x,y), ip(x,y) ), abs(f(x,y)), 1)
splot '++' using 1:2:(color($1,$2)) with pm3d lc rgb variable
The problem is that I need to know the behavior of the function beyond the limit of 5, in this case the behavior in (7,0) or 7+0i
The sampling range is controlled separately from the plot axis range. It defaults to [-5:5], which is what you see in your current plot. To expand the sampling range and expand the displayed axis range also:
set urange [-8:8]; set vrange [-8:8]
set xrange [-10:10]; set yrange [-10:10]
set tics rangelimit scale 0.0
replot

Gnuplot Surface plot combined with heatmap on the same plot in polar coordinates

I'd like to plot 3D surface plot combined with heatmap plot of the same function (from file data) at the bottom (like in the chapter "Combining surfaces with images" in Gnuplot Cookbook).
The wanted picture looks like this and this.
Contour plot is plotted with the script.
Is it possible to draw two graphs (contour and 3D) in the polar coordinates in one plot via Gnuplot?
Output is nothing, so there is an error in the code:
reset
set terminal pngcairo size 800,800 enhanced font 'Verdana,20'
set output '3d-polar_AbsPsiSquared.png'
set lmargin at screen 0.05
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9
set pm3d
unset key
set multiplot
stats '_FullWV.dat' using ($3*$3+$4*$4)
max(a,b) = (a>b) ? a : b
round2(x) = x - floor(x) < 0.5 ? floor(x) : ceil(x)
round(x, n) = round2(x*10**n)*10.0**(-n)
Z_MAX = max(-STATS_min, STATS_max)
Z_MAX = round(Z_MAX,1)
set parametric
set grid xtics ytics
set angles degree
#set zrange[-1,1]
#set cbrange [-1:1]
set autoscale fix
#set autoscale xfix
#set autoscale yfix
set autoscale zfix
#set autoscale
set cbrange [-Z_MAX : Z_MAX]
set palette model RGB defined ( 0"#6495ED", 1"blue", 2"#00008B",3"white",\
4"green",5"yellow",6"red")
#splot '_FullWV.dat' u ($2*cos($1)):($2*sin($1)):($3*$3+$4*$4)
set size ratio -1
set hidden front
set xyplane at -1
splot '_FullWV.dat' u (abs(($3*$3+$4*$4))<1e-3 ? NaN : $2*cos($1)):($2*sin($1)):($3*$3+$4*$4) with pm3d at b, '_FullWV.dat' u (abs(($3*$3+$4*$4))<1e-3 ? NaN : $2*cos($1)):($2*sin($1)):($3*$3+$4*$4) with pm3d
unset multiplot
Seems, the solution is depthorder option of pm3d, so the right script is:
reset
set terminal postscript eps size 5,6 enhanced color font 'Helvetica,20' linewidth 2
set output "3d.eps"
set tics scale 1.25
set xlabel '{/Helvetica-Oblique x, a.u.}'
set ylabel '{/Helvetica-Oblique y, a.u.}'
set zlabel '{/Helvetica-Oblique E, a.u.}'
set pm3d depthorder
unset key
set multiplot
unset colorbox
stats '_FullWV.dat' using ($3*$3+$4*$4)
max(a,b) = (a>b) ? a : b
round2(x) = x - floor(x) < 0.5 ? floor(x) : ceil(x)
round(x, n) = round2(x*10**n)*10.0**(-n)
Z_MAX = max(-STATS_min, STATS_max)
Z_MAX = round(Z_MAX,1)
set parametric
set grid xtics ytics ztics
set mxtics 2
set mytics 2
set tics out
set decimalsign ","
set format x "%.1f"
set format y "%.1f"
set format z "%.0f"
set angles degree
set view 61,33
set ztics floor(Z_MAX/3)
set autoscale fix
set autoscale zfix
set cbrange [0 : Z_MAX]
set palette model RGB defined ( 0"#168de2", 1"#0201db", 2"#00008B", 3"#00dcf5",\
4"#09df67",5"yellow",6"red")
set size ratio 1
set hidden3d front
set xyplane at -10
splot '_FullWV.dat' u (abs(($3*$3+$4*$4))<1e-3 ? NaN : $2*cos($1)):($2*sin($1)):($3*$3+$4*$4) with pm3d at b, '_FullWV.dat' u (abs(($3*$3+$4*$4))<1e-3 ? NaN : $2*cos($1)):($2*sin($1)):($3*$3+$4*$4) with pm3d
unset multiplot

gnuplot - How to make zmin equal to zmax keeeping autoscale on z axis

How one could make resulting output of scaling over z axis symmetric over xy plane: zmax = zmin, keeping autoscale on z axis turning on? (GNUplot 5.0)
resulting graph - 3d-polar.png
Is there this possibility in GNUplot or only fixed range of cbrange can be used?
the example that is used for polar heatmap plot:
reset
set terminal pngcairo size 800,800
set output '3d-polar.png'
set lmargin at screen 0.05
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9
set pm3d map
unset key
set multiplot
set parametric
set grid xtics ytics
set angles degree
set autoscale xfix
set autoscale yfix
set autoscale zfix
set palette model RGB defined ( 0"black", 1"white", 2"grey")
splot '_FullWV.dat' u ($2*cos($1)):($2*sin($1)):3
unset multiplot
The _FullWV.dat file is here.
You can use stats to extract min and max of the 3rd column, and define cbrange accordingly.
reset
set terminal pngcairo size 800,800
set output '3d-polar.png'
set lmargin at screen 0.05
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9
set pm3d map
unset key
set multiplot
stats '_FullWV.dat' using 3
max(a,b) = (a>b) ? a : b
Z_MAX = max(-STATS_min, STATS_max)
set parametric
set grid xtics ytics
set angles degree
set autoscale xfix
set autoscale yfix
#set zrange [-Z_MAX : Z_MAX]
set cbrange [-Z_MAX : Z_MAX]
set palette model RGB defined ( 0"black", 1"white", 2"grey")
splot '_FullWV.dat' u ($2*cos($1)):($2*sin($1)):3
unset multiplot

Gnuplot heatmap coloring error

I have a puzzling issue with heatmapping in gnuplot...
My script have always worked until this bright day, and I cannot figure out why...
The problem is that my heatmap is allright in numbers (as the regions of my heatmap is in the right place with the right data printed on it, but lack of color) but the color is just in the "diagonal" region of it (picture included)
Here is my script which creates the heatmap (I have gnuplot vers. 5.0 patchlvl 3 ):
Set term pngcairo size 680,7000
unset key
set view map
set xtics border in scale 0,0 mirror norotate offset character 0, 0, 0 autojustify
set ytics border in scale 0,0 mirror norotate offset character 0, 0, 0 autojustify
set ztics border in scale 0,0 nomirror norotate offset character 0, 0, 0 autojustify
set nocbtics
set rtics axis in scale 0,0 nomirror norotate offset character 0, 0, 0 autojustify
set title "Paramétertér"
set xlabel"s_{scd}"
set ylabel"s_{scdd}"
xnumtics = 5
ynumtics = 125
set xtics () # clear all tics
set for [i=0:xnumtics] xtics add (gprintf("%g", 0. + i * 0.01) i)
set ytics ()
set for [i=0:ynumtics] ytics add (gprintf("%g", -0.16 + i * 0.001) i)
set xrange [ -0.500000 : 4.50000 ] noreverse nowriteback
set yrange [ -0.500000 : 124.50000 ] noreverse nowriteback
set cblabel "Rákosodás mértéke (db szimuláció)"
set cbrange [ 0.00000 : 30.00000 ] noreverse nowriteback
set palette rgbformulae 33, 13, 10
do for [i=0:49]{
set output 'parameterter_'.i.'.png'
m = 0.2-(i*0.004)
set label 2 at -0.65, 125.0
set label 2 sprintf("mutrata'%g'",m) tc lt 3
plot 'parameterter'.i.'.txt' using 1:2:3 with image , 'parameterter'.i.'.txt' using 1:2:($3 == 0 ? "" : sprintf("%g",$3) ) with labels
unset output
}
Here is the picture bellow:
Sorry if its too trivial, and for my bad english too...:)
Thx!

Gnuplot: part of axis missing in multiplot

I try to make a figure using multiplot, but some axes are weird (see figure). I use epslatex to generate a standalone tex file. It looks like a "box" limits the axis, but I cannot figure out what the corresponding option is.
The code used to generate the figure is below.
reset
set term epslatex color standalone header \
"\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{cmbright}\n"
set output 'correlations.tex'
set pm3d at b
set pm3d map
unset surface
set pm3d corners2color c4
eps = 1.e-6
f(x)=(log(abs(x)/eps+1))*sgn(x)
set palette functions 2*(gray), 1-2*abs((gray)-.5), 2-2*(gray)
zmax = 1
set cbrange [f(-zmax):f(zmax)]
SX=0.8; SY=0.8
set bmargin 0; set tmargin 0; set lmargin 0; set rmargin 0
X0=0.1; Y0=0.1
DX=0.46; DY=0.64
set size X0+SX+DX,Y0+SY+DY
set origin 0,0
#
# Multiplot
#
set multiplot
#
# bottom left
#
set origin X0,Y0
unset colorbox
unset key
set size square SX,SY
xmax = 5
xshift = 0
set xrange [-xmax-xshift:xmax-xshift]
set yrange [-xmax:xmax]
set xlabel '$x_\parallel$'
set ylabel '$x_\perp$'
set xtics -5,5,5
set ytics -5,5,5
datafile = '../Résultats/correl_pm_smooth2f1.0cutoff5.0xMax5.0nX61.dat'
splot datafile u 1:2:(f($3)) w l t '',\
datafile u 1:(-$2):(f($3)) w l t ''
#
# top left
#
set origin X0,Y0+DY
set xlabel ''
set ylabel ''
set xtics ("" -5, "" 0., "" 5)
datafile = '../Résultats/correl_pm_smooth2f0.0cutoff5.0xMax5.0nX61.dat'
splot datafile u 1:2:(f($3)) w l t '',\
datafile u 1:(-$2):(f($3)) w l t ''
#
# top right
#
set origin X0+DX,Y0+DY
set xtics ("" -5, "" 0., "" 5)
set ytics ("" -5, "" 0., "" 5)
datafile = '../Résultats/correl_pm_smooth2f0.5cutoff5.0xMax5.0nX61.dat'
splot datafile u 1:2:(f($3)) w l t '',\
datafile u 1:(-$2):(f($3)) w l t ''
set origin X0+DX,Y0
set colorbox
set xtics -5,5,5
datafile = '../Résultats/correl_pm_smooth2f5.0cutoff5.0xMax5.0nX61.dat'
splot datafile u 1:2:(f($3)) w l t '',\
datafile u 1:(-$2):(f($3)) w l t ''
unset multiplot
I found the answer. With the epslatex terminal, the size and position of the various items refer to the size of the canvas and should thus be contained in the 1x1 box.
Changing the size of the terminal is done via "set term epslatex size 5,5…".

Resources