Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Passing plot file name to plot command

596 views
Skip to first unread message

Yohan

unread,
Jan 18, 2010, 8:03:44 PM1/18/10
to
Dear All,

I am using the Gnuplot python module to display data from a file.

The commands work fine when I run them from the terminal, however I
start running into problems when I try running the same commands from
within python.

I have done plot before, but I had to manually write the file name
into the code. I want to create the function such that the user can
enter the file path and name and then pass this info as a variable
into the plot command.

The function is as follows:

def plot_data(file_name):
g = Gnuplot.Gnuplot()
g('set datafile separator "," ')
g('set commentschars "$"')
g('set style histogram clutser gap -1')

g.plot('file_name using 2:xtic(1), '' u 3 ti col, u 4 ti col') ###
This is the problem line here


When I run the function and pass the path of the file as the input to
the function, I get the error:

line 0: undefined variable: file_name

I can use a print command to see what the variable file_name contains
just before it calls the gnuplot function. It looks something like
this:

'/home/user/data/datafile.csv'

I hope someone out there can help me...

Yohan

unread,
Jan 18, 2010, 10:31:03 PM1/18/10
to

#########

Turns out I fiddled around and figured it out:

plot(file_name + " <commands here > ")

0 new messages