Introduction to Gnuplot (Part II)

This post is in continuation of the post Introduction to Gnuplot.

Generally people want to plot data from a data file. This example uses a data file containing first 10 steps of Fibonacci series. So, on X-axis we have sequence numbers (n) and on Y-axis we have Fibonacci number that appear on that sequence number (e.g. Fibonacci number 8 appears at sequence 7 and so on). The file looks like this:

#n    Fibonacci
0     1
1     1
4     2
5     3
6     5
7     8
8     13
9     21
10    34

You can use any text editor to create the file or download it from here.

Look at the ‘#’ at the beginning of line number 1, it marks line as a comment. Generally column headers are included in data files but you need to mark them as comment otherwise gnuplot will consider it as data.

Now, we will invoke gnuplot from the terminal


plot is the most important gnuplot command. It is used to plot 2D graphs. In this example we want to plot data from fibonacci-10-steps.dat file. (We have assumed that the file is in the current directory so full file path needs not be included here.)

plot 'fibonacci-10-steps.dat'

Yay! We just plotted our first real graph using gnuplot!

Giving it a title

plot 'fibonacci-10-steps.dat' title 'Fibonacci Distribution'


Plot with style

plot 'fibonacci-10-steps.dat' title 'Fibonacci Distribution' with linespoints


plot commands’s with option can be used to style the graph. There are 12 different styles that can be used: lines, points, linespoints, impulses, dots, steps, errorbars (or yerrorbars), xerrorbars, xyerrorbars, boxes, boxerrorbars, or boxxyerror-bars.

In the next post we will talk about creating more complex graphs. Until than you play with the data!

1 comment

Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s