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.


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)



Run the code using

sudo python

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


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.


Leave a Reply

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

You are commenting using your 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

%d bloggers like this: