It would be handy to have gnuplot write particular settings to an output file, ideally in a .svg, because svg appears very well suited for that - so the image file and settings are all together - however, it appears this is not feasible directly in gnuplot.
Working within the wxt and svg terminals, and especially multiplot, I have been able to see how gnuplot might interface with the shell (for example):
! ls ; pwd ; echo $0
, print sin(pi)
, show terminal
. Trouble happens though when trying usual redirection such as > foo.txt
and such - even starting a separate gnuplot
session by script just to get the parameters. In particular, I found this interesting :
output is sent to STDOUT
print output is sent to '<stderr>'
... though I'm not sure what to do with that.
I could use e.g. ! cat gnuplot.inp | grep terminal >> gnuplot.svg
, and dig into further awk/sed
scripting, but before doing that it would help to know if I'm missing any small details in gnuplot
first. Thanks.
PS a trivial question : why is the shell in gnuplot
sh
, when the plain-old linux terminal shell I am using is bash
and SHELL=/bin/bash
? I notice that shell
drops the session into the shell from which gnuplot
was executed - not sure if that will help the task.
CodePudding user response:
1 The usual way to save current settings to a file is the command save "filename"
. There is a script in the gnuplot repository called gpsavediff
(it may or may not be included in your distro's gnuplot package) that compares the saved values to the default settings and keeps only the ones that changed. From a gnuplot session under linux a typical use would be
... do a bunch of stuff to make a plot ...
save "| gpsavediff > myplot.gp"
... do a bunch more stuff ...
# recover original plot
reset session
load "myplot.gp"
- To write specific lines or text to a file is much simpler than you show. For instance
.
set print "session.log" append
print "# This plot looked good on the screen."
print "# At this point the view angles were ", GPVAL_VIEW_ROT_X, GPVAL_VIEW_ROT_Z
print "# I save a PostScript copy to foo.ps"
set term push
set term postscript color
set output "foo.ps"
replot
unset output
set term pop
...
- When invoking a shell, gnuplot uses the libc library function
popen()
. The gory details of popen() are somewhat system dependent but you probably have a man page for it.
gpsavediff script here