Wednesday, May 6, 2020

Gnuplot - Basics

The following pictures could serve as references.
Function Plot
Function Plot

Data File Plots


There are some of the other parameters related to a graph

set grid
set key outside
set xrange [0:10]
set yrange [0:100]
set xtics 1
set ytics 10
set xlabel "number"
set ylabel "square"
set title "Square of the Numbers"
plot x*x

The graph for this script is the following:

Using 'using'

Generally 'using' is to plot columns of a data plot.  The following are 3 ways of representing the same result.

plot 'sta1.dat' using 2:xtic(1) , 'sta1.dat' using 3, 'sta1.dat' using 4 title column, 'sta2.dat' using 3

plot 'sta1.dat' using 2:xtic(1) , '' u 3, '' u 4 ti col, 'sta2.dat' using 3

plot for [COL=2:4] 'sta1.dat' u COL:xtic(1) ti col, 'sta2.dat' u 3

Secondary Axis

We can have secondary axis on the right margin or top margin. The parameters related to those will be starting with x2 or y2 accordingly.  For example x2labels, y2tics, etc.

Here is the example of having two plots with (primary-x-axis, primary-y-axis) and (secondary-x-axis,primary-y-axis) in the same graph.

set xrange [0:10]
set yrange [0:10]
set y2range [-2:2]

set xlabel 'X axis'
set ylabel 'Y axis'
set y2label 'Y2 axis'
set y2tics 1

plot 2*x axes x1y1, sin(x) axes x1y2

The resultant graph is 'sec-axis-1'
Sec-axis-1

The following is another script the uses (primary-x-axis,primary-y-axis) and (secondary-x-axis,secondary-y-axis).

set x2range [-20:20]
set xrange [-10:10]
set y2range [-3:3]
set yrange [-1:1]

set y2tics 1
set x2tics 4

set xlabel "X1 Axis"
set ylabel "Y1 Axis"
set x2label "X2 Axis"
set y2label "Y2 Axis"

plot sin(x) axes x1y1 title "X1-Y1 Axis", cos(x) axes x2y2 title "X2-Y2 Axis"

The resultant graph will be
Sec-axis-2

No comments:

Post a Comment