Thursday, October 6, 2011

Broken axes graph in gnuplot (1)

If the range of data is large, it is not convenient to plot the whole range. Then broken axes graph is introduced. Let us see a broken axes graph at first and then how it is plotted.


To plot a broken axes graph like the upper one, there are two methods. We first introduce the one which is simple to understand and a better but a little tricky one will be talked next time. This method uses the "multiplot" mode, plotting the left and right part of the broken axes graph separately. Let us come to see our script. This script just produce the former graph. The explaination of the script is covered as comments of the script and will not be given separately.

reset
set term png font "Times,15"
set output "broken_axes1.png"
f(x)=exp(-x)*sin(500*x)     #plotting function
set yrange [-1:1]    #The later two plot have same yrange
set sample 400
set tics nomirror
set tmargin at screen 0.9   #the later two plots will share this tmargin
set bmargin at screen 0.1   #------------------------------------b------

set multiplot    #begin multiplot mode

#axes broken line
set arrow 1  from screen 0.5,0.08 to screen 0.52,0.12 nohead
set arrow 2  from screen 0.52,0.08 to screen 0.54,0.12 nohead
set arrow 3  from screen 0.5,0.88 to screen 0.52,0.92 nohead
set arrow 4  from screen 0.52,0.88 to screen 0.54,0.92 nohead

#x,y axis label and title label
set label 1 "Time: t(s)" at screen 0.475,0.025
set label 2 "Signal:U(mV)" at screen 0.025,0.44 rotate by 90
set label 3 center "U=exp(-t)sin(500t)" at screen 0.5,0.95

#The left part
set border 1+2+4    #the right border is not plotted
set lmargin at screen 0.1   #the left-part's location
set rmargin at screen 0.51
set xtics 0,0.02,0.08
plot [0:0.1] f(x) w l lt 1 lw 2 notitle

#unset the labels and arrows, otherwise they will be plot 
#for the second time
unset label 1
unset label 2
unset label 3 

unset arrow 1
unset arrow 2
unset arrow 3
unset arrow 4

#the right part
set border 1+4+8    #the left border is not plotted
set lmargin at screen 0.53      #the right-part's location
set rmargin at screen 0.94
#ytics is not plotted, as the second plot will share it with the first one
unset ytics
set xtics 0.9,0.02,1.0
plot [0.9:1] f(x) w l lt 1 lw 2

unset multiplot

No comments:

Post a Comment

Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.