1
votes

I have a Gnuplot script that draws 2 curves from a data file. If I don't specify yrange, Gnuplot sets it so that all the points of both curves fit in the figure. In my case I would like Gnuplot to only care about one of the curve (it does not matter if the other goes out of range, since I'm interested only in the parts of the figure where the second curve gets close to the first one).

I could find out the minimum and maximum values taken by the first curve, and manually set yrange to those values, but my Gnuplot script is intended to run automatically on many data files, producing many figures for which yrange is not the same, so I'm looking for a way to do that automatically.

Thanks

1

1 Answers

2
votes

There are different options, depending on the used gnuplot version:

Version 5.0:

The data file which should be excluded from the autoscaling gets a noautoscale parameter:

plot 'first.dat' using 1:2, 'second.dat' using 1:2 noautoscale

Version >= 4.6:

Use the stats command to get the minimum and maximum value of the relavant data file:

stats 'first.dat' using 1:2
set yrange [STATS_min_y:STATS_max_y]
plot 'first.dat' using 1:2, 'second.dat' using 1:2

At least since 4.0:

Use set yrange [] writeback to save the autoscaled ranges from a plot command and set yrange restore to use them for a later plot:

set terminal push
set terminal unknown

set yrange [] writeback
plot 'first.dat' using 1:2

set yrange restore
set terminal pop
plot 'first.dat' using 1:2, 'second.dat' using 1:2