Installing Gnuplot on the Raspberry Pi

Gnuplot produces graphs from a file with the extension .dat Install Gnuplot on the Raspberry Pi using the following command

sudo apt-get install gnuplot-x11

answering Y when required. Once Gnuplot is installed the following python programme can be used to generate some data.


#!/usr/bin/python

import math

f = open('mydata.dat', 'w')

# Loop

for degrees in range(720):
    # Generate data points
    si = math.sin(math.radians(degrees))
    # Write 3 data points to text file
    data = "{} {}\n".format(degrees, si)

    f.write(data) 

f.close()

Run the code using

sudo python gnuplot_generate_data.py

and this will generate a file that can be used by Gnuplot. Now open a terminal window and type in

gnuplot

The program will start and at the prompt type

plot "mydata.dat"

and the graph will be plotted

 

It is possible to change axis, add titles and much more.  A good guide as to what can be achieved with Gnuplot can be found here.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s