Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot: more than 2 datasets in single plot with 2 y-axes

I have multiple datasets I want to plot in a single figure:

plot "data1a.txt", "data1b.txt", "data1c.txt", "data2.txt"

I want to have two y-axes with different ranges.

yrange=[0:10]
y2range=[-10:10]

This is easily done on gnuplot if you only have two datasets. The first dataset uses yrange (with it's axis on the left hand side), and the second dataset uses y2range (with the axis on the right hand side).

Now here's the question. I want to plot datasets data1a.txt, data1b.txt and data1c.txt using yrange, and data2.txt using y2range. How do I do this on a single figure with two y-axes?

like image 766
Eddy Avatar asked Aug 20 '12 09:08

Eddy


1 Answers

As documented here:

plot {<ranges>}  
      {<function> | {"<datafile>" {datafile-modifiers}}}  
      {axes <axes>} {<title-spec>} {with <style>}  
      {, {definitions,} <function> ...} 

you can see that the axes are used in the plot command. After setting the ranges of your y-axes with

set yrange [y1min:y1max]
set y2range [y2min:y2max]

you can specify which axis you want to use in your plot with

plot "data.txt" axes x1y1

if you want to plot it against the first y-axis or

plot "data.txt" axes x1y2

if you want to plot it against the second y-axis.

Also see this example of how to use multiple axis in gnuplot.

like image 141
Woltan Avatar answered Sep 27 '22 20:09

Woltan