0

I am new to gnuplot. I am using Unix.

I see the commands/error and their output on the terminal but I want to save them on a file too for storage purposes.

There is a save command in gnuplot but it only saves the last plot or splot command given by the module and the final settings.

Suppose I plot a line with settings 'A' and after doing some calculation I went and re-plotted another line with setting 'B'

gnuplot.save() command would only save the last command and the latest settings. How can I save all the issued commands?

Kindly help...

1
  • You could use matplotlib to make your plots entirely in python. Commented May 21, 2012 at 18:08

2 Answers 2

1

I'm not extremely familiar with gnuplot-py -- but if it writes the commands to the terminal as it executes them, you can just use shell redirection:

python myPythonScriptWithGnuplot.py > commandfile.gp  #redirect stdout
python myPythonScriptWithGnuplot.py 2> commandfile.gp  #redirect stderr

Of course, this won't help if you're writing other things to the terminal from python ...

But note that gnuplot-py sends the data to gnuplot via a temporary FIFO (I think anyway). So, if you're plotting data (e.g. lists, numpy arrays, etc ... not functions like "sin(x)"), when you try to plot the data, the FIFO will have been purged from your system and your plot command will fail complaining it can't find the datafile.

EDIT

After a (quick) look at the source, it appears you have a few options. Your first option: pass debug=1 to the constructor (You already might be doing this). This will cause the commands to be written to standard-error. with a little (or a lot) of shell magic, you can separate out the different output streams. Here's a recipe to put stderr from a command into a file while still leaving the output on your terminal that works in bash (I'm using bash 4.1.5 -- but I'm pretty sure this has been around for a while):

((command 3>&1 1>&2 2>&3 ) | tee command_stderr.log ) 3>&1 1>&2 2>&3
          #swap stderr/out  
                             #tee puts data in output file and to terminal
                                                      #swap stderr/stdout again.

(I'd love to see a cleaner way to do this output stream swapping if anyone knows it...)

Alternatively, you can pass a filename to the Gnuplot constructor. This will write the commands to that file. As far as I can tell, there's no method to allow you to write the commmands to the file and to the gnuplot pipe. However, you can always start up multiple Gnuplot instances and write the commands to a file via the main instance and then whenever you write a plot command, tell the second instance to load "filename". Of course, if you use this method, you should probably specify that the data should be inlined.

A third option is to abandon gnuplot-py in favor of pyGnuplot since I'm still actively developing that one -- Then if something doesn't work, or you'd like to have a feature added, you can just let me know ;)

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

2 Comments

Redirection will work but i also want to show my results on the terminal too.
@varun : I've edited with a way that you can manipulate the output streams so that it will hopefully leave the commands on the terminal, but also put them into a file for future reference.
0

Non-python answer would be to use `script' command.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.