1

I would like to save the set commands used to define my graph.

Basically I would like to save the style of the line, the color, output name, ranges and so on; in a file

Then I would like to call it from a script, like

gnuplot <setting script name> <data file> "plot <plot commands>" 

Is this possible? The manual don't mention any kind of capability to load the options that you set for the plot function, from an external file.

2 Answers2

1

There are several approaches.

You can store very general settings in a ~/.gnuplot file.

Otherwise, you can make a script, named myplot, which constructs it locally

#!/bin/bash
gnuplot << EOF
<all settings>
plot "$1"
EOF

Which you call by ./myplot <datafile>

Bernhard
  • 3,619
  • 1
  • 25
  • 50
  • Thanks Bernhard, Sorry, I didn't realize that I can append the rest of the options after the $1 :) Is almost 3 AM and my brain is starting to leave me behind –  Feb 03 '14 at 10:34
0

You can, e.g. put all settings in one file e.g. settings.gp

set terminal ...
set xtics ...

Have one file plot.gp which contains all plotting commands which use a variable datafile:

plot datafile using 1:2

The variable datafile can be given using the -e option, and the settings file can be loaded with load

gnuplot -e "datafile='mydatafile.dat'; load 'settings.gp'" plot.gp

See also How to pass command line argument to gnuplot?

Community
  • 1
  • 1
Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Much appreciated Christoph; it is a good variation on the method that Bernhard posted. Altho it requires basically 3 files: one with the settings, the datafile and the script that launch the whole thing; while in the other solution, you have only the script and data file, so it fits perfectly my case. Thanks! –  Feb 05 '14 at 22:58
  • That was the way how I plotted all the graphs of my thesis: One main file with general settings, a plotting file, which could be changed with a few variables given by the `-e` parameter to produce several, similar plots. – Christoph Feb 05 '14 at 23:02