Ondřej Skládal
Ondřej Skládal

Reputation: 31

How to set xrange on command line in gnuplot

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

Upvotes: 1

Views: 1535

Answers (3)

Ethan
Ethan

Reputation: 15093

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.

Upvotes: 1

Mark Setchell
Mark Setchell

Reputation: 207465

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

Upvotes: 0

meuh
meuh

Reputation: 12255

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]

Upvotes: 0

Related Questions