A6. Two axes and a model
Goal: the residual (log) and the drag coefficient (linear) on one plot, each on its own scale, and a model function over the data.
gnuplot
set logscale y
set ylabel 'continuity residual'
set y2label 'cd'
set ytics nomirror
set y2ticsgnuplot
plot 'run.dat' using 1:2 title 'continuity', \
'' using 1:5 axes x1y2 with points pt 7 ps 0.6 title 'cd', \
0.30 + 0.25*exp(-x/25)*cos(x/6) axes x1y2 dt 2 title 'model'Why it works
axes x1y2plots an item against the second y axis, autoscaled on its items alone.- As in gnuplot, the y2 ticks are off until
set y2tics;set ytics nomirrorkeeps the y ticks off the right border.set y2label,set y2range,set logscale y2andset format y2work as for y. - An item that is not a quoted file is a function of
x, with the operators ofusingexpressions. It is sampled atset samplespoints (100) over the x range of the data — here the iterations, 1 to 120 — and titled as written. Functions are drawn with lines unlesswithorset style functionsay otherwise.
Try this
fit f(x) 'run.dat' u 1:5 via a, bwithf(x) = a + b*exp(-x/25): the model's parameters from the data, thenplot ..., f(x) axes x1y2.set link y2 via y*1e4 inverse y/1e4: a second axis that is the first one rescaled, gnuplot 6.0's way.
Pitfalls
- Two axes on one plot are easy to misread: label both, and say in the key which axis a series uses (
cd (right)). - A function samples the x range of the data: alone (
plot sin(x)) it uses[-10:10], gnuplot's default.
Reference: second y axis, functions. Next: path B, watching a simulation.