Using a certain program (PersistenceLandscapes toolbox) I am generating a large number of scripts from which I generate plots with gnuplot. I iterate through the files and make gnuplot show the plot with the command gnuplot gnuplotCommand.txt -p
. How can I make gnuplot save the plot in, say, PNG or (preferably) EPS format? (I want to avoid meddling with gnuplotCommand
-type scripts.)
2
votes
3 Answers
2
votes
3
votes
2
votes
If you have gnuplot version 5.0, you can pass arguments to your script. For example,
# script.gp
if (ARGC > 1) {
set terminal ARG2
set output ARG3
print 'output file : ', ARG3, ' (', ARG2 , ')'
}
# load the script needed
load ARG1
This script must be called with option -c
gnuplot -c script.gp gnuplotCommand.txt pngcairo output.png
In this example, we have set the variables ARG1=gnuplotCommand.txt
, ARG2=pncairo
, and ARG3=output.png
. The number of arguments is ARCG=3
. Also, it has been set ARG0=script.gp
as the name of the main script.
If you just want to see the output, without saving it to a file, you can call this script as:
gnuplot -p script.gp gnuplotCommand.txt
You may want to check if the user has given a name for the output file. If not, we can use a default name:
if (ARGC > 1) {
if (ARGC < 3) { ARG3="default" } # without extension... it doesn't matter in linux :)
set terminal ARG2
set output ARG3
print 'output file : ', ARG3, ' (', ARG2 , ')'
}