1

I have several gnuplot scripts that draw graphs for me. I need to set the same xrange values ​​on the command line for everyone gnuplot scripts. I don't want to open each one separately.

Code in gnuplot scripts(name:tlakD.gnuplot):

set xdata time 
set timefmt "%m/%d/%Y %H:%M" # specify time string format
set xrange datum
set format x "%d/%m/%Y "

Command line attempt: gnuplot -e "datum='["1/1/19 12:00":"1/5/19 11:59"]'" tlakD.gnuplot

Second attempt: I removed the xrange.

Code in gnuplot scripts(name:tlakD.gnuplot):

set xdata time 
set timefmt "%m/%d/%Y %H:%M" # specify time string format
set format x "%d/%m/%Y "

Command line attempt: gnuplot -e "xrange='["1/1/19 12:00":"1/5/19 11:59"]'" tlakD.gnuplot

An idea of ​​what I want: gnuplot -e "xrange='["1/1/19 12:00":"1/5/19 11:59"]'" tlakD.gnuplot ; vlhkosD.gnuplot; teplotaD.gnuplo and many more gnuplots scripts I want to run all scripts with the same xrange. Thanks

3 Answers3

1

I suggest to put the range command in a separate file and invoke both the range file and the plot file in the command. You could even have a collection of range files and choose the one you want at the time of plotting.

 gnuplot setrange_1.gp tlakD.gp

It is not necessary to use the -e construct here. gnuplot will execute each file listed on the command line in the order given, as if they had been concatenated into a single larger file prior to execution.

Ethan
  • 13,715
  • 2
  • 12
  • 21
  • I also tried this method, unfortunately it doesn't work. Command line writes: Can't plot with an empty x range! In separate file(name:nastav.gp) is : `set xrange ["1/1/19 12:00":"1/5/19 11:59"]` In command line: `gnuplot nastav.gp tlakD.gnuplo` – Ondřej Skládal May 07 '20 at 09:42
  • I assure you that the method works. I suggest to start with a working sequence of commands, then split it into a first part in one file and a second part in another file. – Ethan May 07 '20 at 17:24
  • You could also use the command line construct `cat file1 file2 | gnuplot`, although I can't think of any advantage to doing it that way. – Ethan May 07 '20 at 17:26
0

It doesn't seem you can specify a range [...:...] in one variable, but you can do so in 2 separate string variables:

gnuplot  -e a='"1/1/19 12:00"' -e b='"1/5/19 11:59]"'

set xrange [a:b]
meuh
  • 11,500
  • 2
  • 29
  • 45
0

I created a data.txt file like this:

"2/1/2019 10:00:00" 4
"3/1/2019 10:00:00" 8
"4/1/2019 10:00:00" 16
"5/1/2019 10:00:00" 32

The commands I would run inside gnuplot would be:

set timefmt '"%d/%m/%Y %H:%M:%S"'
set xdata time
set xrange ['"1/1/2019 12:00"':'"1/5/2019 11:59"']
plot "data.txt" using 1:2

So, that means my bash command line would be:

gnuplot -p \
        -e "set timefmt '\"%d/%m/%Y %H:%M:%S\"'"                    \
        -e "set xdata time"                                         \
        -e "set xrange ['\"1/1/2019 12:00\"':'\"5/1/2019 11:59\"']" \
        -e "plot \"data.txt\" using 1:2"

enter image description here

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432