1

I am just about to find out how python and gnuplot work together. On

http://wiki.aims.ac.za/mediawiki/index.php/Python:Gnuplot_module

I found an introduction and I wanted to execute it on my Ubuntu machine.

import Gnuplot  

gp = Gnuplot.Gnuplot(persist = 1)  
gp('set data style lines')  

# The first data set (a quadratic)  
data1 = [[0, 0], [1, 1], [2, 4], [3, 9], [4, 16]]

# The second data set (a straight line)          
data2 = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]]     


plot1 = Gnuplot.PlotItems.Data(data1, with_="lines", title="Quadratic")  
plot2 = Gnuplot.PlotItems.Data(data2, with_="points 3", title=None)  # No title  

gp.plot(plot1, plot2) 

However, I get the following error message:

./demo.py   
./demo.py: line 2: syntax error near unexpected token `('  
./demo.py: line 2: `gp = Gnuplot.Gnuplot(persist = 1)'  

any idea what could be wrong here? To install gnuplot support for python I installed python-gnuplot. Do I miss another package?

1
  • Is this "gnuplot support for Python" the same thing as Gnuplot.py? Try installing it, and running its demo (which is what it looks like you're attempting above): gnuplot-py.sourceforge.net Commented Jul 29, 2009 at 15:51

5 Answers 5

2

Did you put the bangline in the first line? i.e:

#!/usr/bin/python

Looks like it is not the Python interpreter who is executing the file.

Sign up to request clarification or add additional context in comments.

1 Comment

yep, looks like you are running it through the bash interpreter here. if it were me, i'd user #!/usr/bin/env python as the bang line for unix. or run it manually with "python demo.py"
0

Well the python interpreter thinks that while parsing there was an syntax error. Check again your quotes, make sure that for convenience sake you only use either double or single quotes in your entire script (except of course when you need to put in a literal quote like "'" or '"').

If you are unsure what goes wrong what you can do is open the interactive interpreter and write each line in there.

Comments

0

Your demo.py file is somehow corrupted - make sure that the open-parenthesis character is really that. Grub the installer from the project page to make sure.

You can access the current SVN version of the file (choose download of the HEAD revision).

Comments

0

If I copy and paste your code into Emacs I get this:

gp = Gnuplot.Gnuplot(persist = 1)
 gp('set data style lines') 
data1 = [[0, 0], [1, 1], [2, 4], [3, 9], [4, 16]] # The first data set (a quadratic)
 data2 = [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]] # The second data set (a straight line) 
plot1 = Gnuplot.PlotItems.Data(data1, with_="lines", title="Quadratic")
 plot2 = Gnuplot.PlotItems.Data(data2, with_="points 3", title=None) # No title 
gp.plot(plot1, plot2)

If I remove the whitespaces at the beginning of the three lines it works for me.

Comments

-1

I've been using pylab instead. Pylab homepage

From debian repos:

python-matplotlib - Python based plotting system in a style similar to Matlab.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.