Trix & Graphix

Plots inside other plots with Gnuplot

This is another post when I'm going to try to explain how to use the multiplot environment. In this case, I'm going to use the multiplot environment, but setting the position of the plots "by hand" in order to get the effect of one plot inside other. This may be useful if you want to show some detail of a small part of the general plot. This is the final result:

Well, the overall idea is the same than in this other post, but in this case I won't use the automatic layout. In order to set the size and position of the plot manually, you have to use the parameters size and origin, respectively. You have to know that the units of these commands are the size of the whole figure, and first number refers to x axis. Then for example, set size 1,1 means use the whole figure as the size of the plot. Analogously, set origin 0.5,0.5 sets the bottom left corner of the plot in the centre of the figure.

Other example: if you want to insert two plots, one over the other, you could set size 1,0.5 in order to reduce the vertical size to half the total, and then use set origin 0,0.5 before plotting the second graph.

This is the code to generate the figure above. I have plotted also a rectangle and an arrow. You can skip that, it's not really important, but I just wanted to show some more capabilities of Gnuplot.

gnuplot << TOEND
set terminal postscript eps color enhanced
set output 'multiplot2.eps'

#set ytics 0.25
#set format y "%.2f"

set multiplot


# Bigger plot options
set yrange [-4:5]
set size 1,1
set origin 0,0
set title 'Whole plot'
set xlabel 'time/s'
set ylabel 'variable/m'


### This is to plot the square. You can skip this ###
set arrow from 1.1,-0.9 to 1.0,0.3 lw 1 back filled
set arrow from 0.9,-3 to 1.5,-3 lw 1 front nohead
set arrow from 0.9,-1 to 1.5,-1 lw 1 front nohead
set arrow from 0.9,-1 to 0.9,-3 lw 1 front nohead
set arrow from 1.5,-1 to 1.5,-3 lw 1 front nohead
###################################

# This plots the big plot
plot 'datos.dat' w l lt 1 lc 3 lw 3 t ''

# Now we set the options for the smaller plot
set size 0.6,0.4
set origin 0.2,0.5
set title 'Zoom'
set xrange [0.9:1.5]
set yrange [-3:-1]
set xlabel ""
set ylabel ""
unset arrow
set grid

# And finally let's plot the same set of data, but in the smaller plot
plot 'datos.dat' w l lt 1 lc 3 lw 3 t ''

# It's important to close the multiplot environment!!!
unset multiplot

TOEND

0 Comments: