Tuesday, September 25, 2012

Introduction to Gnuplot

Simple Plotting with Gnuplot

Gnuplot is a powerful command line driven plotting program that is available for Windows, Mac and linux (and others). It is freely available to install and use. The application has two main features: it allows us to interactively plot mathematical functions and data at the command line; and also to create scripts that can analyse data or just create hundreds of figure plots simultaneously.

The big advantage for scientists is the ability to quickly review results from numerical calculations. Rather than waiting minutes to load up a spreadsheet program and create a plot results can be viewed almost instantly.

Please see other posts [1] for how to install and use on different operating systems. In this tutorial we shall use a terminal on the linux based Ubuntu DE to demonstrate the commands. The commands themselves are the same regardless of which operating system we work on. For a full list of commands and a more indepth look at the program you can find the official docs here

Gnuplot Official Guide (pdf)

Open a new terminal and type gnuplot into the command line. You should see the following:


Now enter the following command, press return

plot sin(x) with lines

and you should see


Inputting other functions is relatively simple, the syntax is similar to that found on other popular mathematical programs such as matlab. You can also store parameters, create functions and change them interactively, for instance enter the following code

a = 1.4
b = 0.13
f(x) = a * exp(-b*x*x)
plot f(x) with lines

which appears on screen as


Now we can add labels, change the distance between tics, the range/domain, and add rename the key with the following


set xlabel "x"
set ylabel "y"
set xtics 4
set ytics 0.25
set xrange [-8:8]
set yrange [0:1.5]
plot f(x) title "My Function" with lines


Try experimenting with different functions and changing the properties of the plot. Next try plotting 2D and 3D data from files in the post " Plotting 2D and 3D data with Gnuplot ".

7 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. hi, very nice blog post .thank you for sharing valuable information. SLN Ventures provides agriculture land for sale in hyderabad with ample greenery, modern designs that are luxurious, offer good spaces and thoughtful amenities thereby enhancing the property’s value and giving the customers a good return on their investments.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. I am glad to see this nice blog and I found this kind of information i was also searching for this kind of information I found. if you want to know something about server hosting then see you should know about USA VPS Hosting and how it can be important for this modern world. Thanks once again.

    ReplyDelete