I'd like to make gnuplot scripts to output *.eps files and change them into .pdf type automatically. I have a test demo which goes as:
set term postscript eps enhanced color
set output "SystemCommand.eps"
plot sin(x)
set xl "x"
set yl "y=sin(x)"
system(sprintf("epstopdf %s",SystemCommand.eps))
but it doesn't produce what I want, an error comes out every time that says:
"SystemCommand.gp", line 6: undefined variable: SystemCommand
I have tried to use SystemCommand or SystemCommand.eps, no difference here. Anyone has a suggestion?
I use Ubuntu 14.04 and bash shell.
You need to quote the filename in sprintf.
set term postscript eps enhanced color
set output "SystemCommand.eps"
plot sin(x)
set xl "x"
set yl "y=sin(x)"
system(sprintf("epstopdf %s","SystemCommand.eps"))
Related
I have some data I would like to plot in gnuplot. For being able to plot them I wrote a script called "plot_A.gp". In it I set the axis values, labels and the output terminal.
In order not to have it modificated for every data file, I was wondering if it is possible to make the script able to handle drag and drop-files.
As example script:
set xrange [0 to 100]
set xlabel "x-axis"
set ylabel "y-axis"
set terminal eps
set output %1.pdf
plot %1 using 1:($2*$2) with lines
How can I set %1 to the file name I just dropped onto the script?
Please execute the script with call instead of load at the gnuplot prompt. call accepts upto 10 arguments. Before gnuplot 5.0, these arguments are called $0, $1, ..., $9.
In gnuplot 4.6, your script would look like this:
datafile="$0"
outputfile="$0".".pdf"
set xrange [0 to 100]
set xlabel "x-axis"
set ylabel "y-axis"
plot "hello" using 1:($$2*$$2) with lines
set terminal eps
set output outputfile
replot
set terminal wxt
set output
Because $2 refers to the third parameter to the script, to access the second column use $$2 instead. Alternately, you can also use 1:(column(2)*column(2)).
You would call it like this.
gnuplot> call "plot_A.gp" "hello"
This will plot the data in the file "hello" and create a pdf called "hello.pdf". I have also reset the terminal back to wxt, as a best-practice.
From gnuplot 5.0, using $0, $1 etc is deprecated. Instead you should use the special variables ARG0, ARG2, ..., ARG9. I don't have access to gnuplot 5.0. But I think you just need to use ARG0 instead of $0. Please you could refer to this answer to How to pass command line argument to gnuplot?
I have the following gnuplot script:
set autoscale
unset log
unset label
set xtic auto
set ytic auto
unset title
set xlabel "Number of clusters"
set ylabel "Accuracy of classifier (%)"
plot "cluster.dat" using 1:3 title "PART" with lines, \
"cluster.dat" using 1:4 title "JRip" with lines, \
"cluster.dat" using 1:5 title "FURIA" with lines
I would like this script, when run, to output SVG or EPS - what would I need to add or modify to make this happen?
In gnuplot the output type is called terminal.
In your script, before the plot command use
set term svg
set output "output.svg"
or
set term eps
set output "output.eps"
both terminals have several options. Type help eps (on some gnuplot this is help epscairo) or help svg.
To get the list of available terminals for your build, type set terminal.
I thought I knew how the {/Symbol x} worked in gnuplot but I don't. I need to get a partial derivative symbol (utf8 code U+2202), and I can't. How could I do it. I haven't found anything online. This is the document settings:
set terminal postscript eps enhanced color font "Helvetica, 20"
set encoding utf8
Thank you
If you really need to use a postscript terminal, use
{/Symbol \266}
Your gnuplot distribution should contain the file ps_guide.ps. That explains all the character codes available in postscript.
In general I would second Christoph's suggestion to use a cairo terminal. In combination with UTF-8 input encoding and a proper font you can easily include more characters in your output.
When I generate plots for inclusion in TeX documents, I tend to use the same font as the body text (in the example below "TeX Gyre Pagella")
set terminal pdfcairo enhanced color dashed font "TeX Gyre Pagella, 14" \
rounded size 16 cm, 9.6 cm
set encoding utf8
Use any of the cairo-based terminal (pdfcairo or epscairo) and insert the character directly into your script:
set encoding utf8
set terminal pdfcairo font ',20'
set output 'partial-derivative.pdf'
set xlabel '∂u/∂x'
plot x
When creating symbols in combination with the epslatex terminal in Gnuplot 4.6, I always notice that in the center of the symbol a small dot is shown (clearly visible on zoom-in). This annoys me quite a bit, as it does not happen in, for example, the png terminal of Gnuplot.
Is there a simple method in Gnuplot to get rid of this dot?
Minimum reproductive example:
set terminal epslatex
set output "test.tex"
test
It can be directly observed in the outputfile test.eps.
Additional info:
I use the following code to create a complete eps-file out of it
\documentclass{article}
\usepackage{graphics}
\usepackage{nopageno}
\usepackage{txfonts}
\usepackage[usenames]{color}
\begin{document}
\begin{center}
\input{test.tex}
\end{center}
\end{document}
Is there a solution inside gnuplot?
According to this answer: https://stackoverflow.com/a/16358393/1134387 there are much more symbols than the few shown by test in Gnuplot. When using 64, 65 and 66 as pointtype, I get symbols without the dot inside, which effectively solves my problem.
Since an other question (Removing dot from centre of empty gnuplot point) has been marked as "duplicate" with no more possibility to answer, I put my answer here to provide some test code and images.
You can do a point test sequence yourself in any terminal.
### Terminal test dots
reset session
set colorsequence classic
set terminal postscript color
# set terminal pngcairo
# set terminal pdfcairo
# set terminal qt
# set terminal wxt
set output "TestDot.eps" # in case of file output set the extension according to terminal
N = 160
M = 10
set parametric
set xrange [-0.5:M-0.5]
set yrange [-M/2:N]
set xtics 1
set ytics M
plot for [i=0:N-1] i%M,floor(i/M)*M w p pt i ps 3 notitle
unset parametric
set output
### end of code
postscript terminal:
pngcairo terminal:
Just thought I'd document this (self-answer to follow):
When working with gnuplot in terminal, one can use up and down arrows on keyboard to iterate through the typed commands history - just like in gdb.
However, sometimes there may be a sequence of commands I repeat often - which I'd like to call by issuing a single command. For instance, one works with interactive x11 terminal in gnuplot, and wants to obtain a "screenshot" in png format. That requires the terminal to be changed to png, output to be set, plot to be issued, and terminal reverted back to x11; or:
set terminal png
set output 'gnuplot.png'
replot
set terminal x11
I'd like this sequence to be called with a single command - even though I'm aware that these could fit on a single line, by using semicolon as separator:
set terminal png ; set output 'gnuplot.png' ; replot ; set terminal x11
In gdb, there is a command, define, which allows for user-defined commands; one simply issues in the gdb terminal:
(gdb) define fn
> finish
> next
> end
... and from that point on, one can type fn in that terminal to call the sequence of finish and end.
Is there something similar to that in gnuplot?
Yes, there seems to be - there is a facility called macros (help macros in gnuplot), where a string variable can be expanded by prepending the # ("at" character) to its name.
This facility is disabled by default, so one needs to think about enabling it. Which is why its best to save that sequence in an init script file, named for instance init.gp:
print ""
print "init.gp starting"
set terminal x11
# define capt string variable as sequence
# of commands, semicolon separated
capt = "print 'Saving...' ; set terminal png ; set output 'gnuplot.png' ; replot ; set terminal x11"
print "macros state: "
show macros
print "enabling macros state:"
set macros
show macros
print "The #capt command should be available now."
print ""
print "init.gp ending"
print ""
Then one can do a terminal session like this in gnuplot:
$ gnuplot
G N U P L O T
[...]
Terminal type set to 'wxt'
gnuplot> load "init.gp"
init.gp starting
macros state:
command line macros will not be expanded
enabling macros state:
command line macros will be expanded
The #capt command should be available now.
init.gp ending
gnuplot> plot sin(x)
gnuplot> #capt
Saving...
Terminal type set to 'png'
Options are 'nocrop font /usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf 12 size 640,480 '
Terminal type set to 'x11'
Options are ' nopersist'
gnuplot> plot cos(x)
Closing gnuplot.png
gnuplot> exit
$ identify gnuplot.png
gnuplot.png PNG 640x480 640x480+0+0 8-bit PseudoClass 102c 5.58KB 0.000u 0:00.000
Well, hope this helps someone,
Cheers!