In gnuplot, using the commands
set term pdf
set out 'filename.pdf'
plot sin(x)
allows me to write the image to a pdf. After doing so, how do I reset the output so that plot sin(x) creates the image using the built-in gnuplot display (as it does without ever have using set out in the first place).
Right now I can only acheive this by restarting gnuplot. The reset command does not seem to help. Thanks all!
In addition to the other answer, you could do:
set term pop
set output #reset standard output stream
In general, you can save the terminal settings you're currently working one using:
set term ... #what you want to save
set term push
set term ... #temporary terminal
set term pop #restore the terminal settings that you "pushed"
However, as documented in help set terminal:
The command set term push remembers the current terminal including its
settings while set term pop restores it. This is equivalent to save term
and load term, but without accessing the filesystem. Therefore they can be
used to achieve platform independent restoring of the terminal after printing,
for instance. After gnuplot's startup, the default terminal or that from
startup file is pushed automatically. Therefore portable scripts can rely
that set term pop restores the default terminal on a given platform unless
another terminal has been pushed explicitly.
Assuming you have the X11 version of gnuplot installed. Set the terminal back to x11 and reset the output
set term x11
set out
Related
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.
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
I am using gnuplot over ssh (-X) and due to different screen resolution issues, my x11 output window has minuscule fonts. I want to access the .Xdefaults file as mentioned in documentation but cannot locate it. This question GNUPLOT_DRIVER_DIRECTORY pointed towards some solution but I don't want to input it every time. Can someone help me find a permanent fix for font sizes?
What is your default terminal ? I think it shoulds be xterm, to have x11 as defaults.
shell> echo $TERM
What is yout default gnuplot terminal display ?
gnuplot> show term
Instruction in ~/.Xdefaults have a special syntax (some example in linuxcertif.com/man/1/gnuplot/ ). But i think that's not what you want to do. This is more for 'fine tuning'. And i think it will only be effective if your default terminal is allready x11.
gnuplot*pointsize: 2
gnuplot*background: white
gnuplot*textColor: black
Anyway, it is better to use gnuplot with a text file : file.gp where you put your commands. Then just put in the beginning of your file :
set term x11 font "arial,15"
And execute your file with :
shell> gnuplot file.gp -
do not forget the 'dash' '-' at the end of the command, so that you can continue to put command in the gnuplot prompt to debug additional command.
I haven't found anything to my specific Problem with Gnuplot in other Threads. I want to load a text file on Mac. When I tell Gnuplot to
load '/Users/name/Desktop/test.rtf'
it always says Cannot open script file.
I already made sure, that I'm in the right working directory (I guess):
pwd
gives /Users/name
The text file contains:
plot sin(x)
and the standard terminal I'm using is
terminal type is wxt 0 enhanced
I hope someone can help me with that, since I'm not experienced in using programs with the terminal, so I really don't know how to solve my Problem right here.
first of all thanks for your answer! So I just managed to find my mistake, it seems that it has to do something with the notation, since I'm working on a german Mac. So
load 'file'
makes Problems, while
load "file"
works fine for me. Unfortunately I still have the Problem, that
set terminal postscript eps enhanced
set output "/Users/name/Desktop/testplot 2.png"
set encoding default
p sin(x)
set terminal wxt 0 enhanced
gives me a file, that can't be opened and it says the file is probably damaged or the format is not supported by 'preview'. It is not a huge problem actually since I can save the plot manually from the wxt terminal, but I really don't understand what Gnuplot is doing on OS X...
I'm looking for a way to load a custom command to my gnuplot sessions. Often after playing around with a plot I want to output it to PDF, and continue working. This will look like:
set terminal pdf
set output 'somefilename.pdf'
replot
set terminal qt
replot
Currently the best I can do is put that in a separate file with the file name a variable instead of a string, define said variable in my session, then load said file. I'm wondering if I can load this script as a command that takes an argument, so I can do something like
exportpdf "myfile.pdf"
I think your your current method is already pretty good, but if you want you can fine-tune it a little bit:
If you are willing to keep storing the name of the file in a gnuplot variable FILENAME, then you can circumvent the need of an external file by using macros:
exportpdf="set term push; set term pdf; set output FILENAME; replot; set output; set term pop"
You can then save your current figure by executing
#exportpdf
If you want to give the filename as an argument you can create a script file exportpdf.gp
set term push
set term pdf
set output ARG1
replot
set output
set term pop
and define the string
exportpdf='call "exportpdf.gp"'
for example in your startup file. Then you can save your current figure to filename simply by executing
#exportpdf "filename.pdf"
if you want to define a custom "function", you could first construct the appropriate command and then evaluate it:
plotPdf(fname) = eval(sprintf("set terminal pdf;set output '%s';replot;set terminal qt;replot;", fname))
this definition can be then conveniently placed in the Gnuplot startup script so that it is automatically available
In interactive mode gnuplot remembers all the settings for the current plot. It knows what to do when I type 'replot'. So, is there a way to dump all of the current settings into a script file?
See the save command.
You use it as follows:
save "My_stuff_goes_to_this_file.txt"
Here's a (small) excerpt from the docs:
The save command saves user-defined functions, variables, the set
term status, all set options, or all of these, plus the last plot
(splot) command to the specified file.
Syntax:
save {option} 'filename'