No, there is no way to auto-scale the x- and y-range for the same values. Here is a solution on how you can do this with some tricks.
If you want gnuplot to extend ranges to the next ticks, you can do it like this:
You must first build once using the unknown terminal. This stores the x and y ranges in the gnuplot variables GPVAL_X_MIN , GPVAL_X_MAX , GPVAL_Y_MIN and GPVAL_Y_MAX . Then you set the ranges and replot:
set terminal push # save current terminal set terminal unknown plot 'datafile' set terminal pop # restore previous terminal min = (GPVAL_Y_MIN < GPVAL_X_MIN ? GPVAL_Y_MIN : GPVAL_X_MIN) max = (GPVAL_Y_MAX > GPVAL_X_MAX ? GPVAL_Y_MAX : GPVAL_X_MAX) set xrange[min:max] set yrange[min:max] set size ratio -1 replot
The push / pop stuff is only needed if you want to save the initial settings of the terminal.
To make it reusable, for example, for use with multiplot you can wrap all of these commands inside a string and call eval on it:
autoscale_xy(datafile) = \ "set terminal push; set terminal unknown; set autoscale;".\ "plot '".datafile."'; set terminal pop;".\ "min = (GPVAL_Y_MIN < GPVAL_X_MIN ? GPVAL_Y_MIN : GPVAL_X_MIN);".\ "max = (GPVAL_Y_MAX > GPVAL_X_MAX ? GPVAL_Y_MAX : GPVAL_X_MAX);".\ "set xrange[min:max]; set yrange[min:max];" ... files = "first second third fourth" do for [f in files] { eval(autoscale_xy(f)) plot f }
Another option is to use stats to calculate the maximum and minimum values ββof x and y and set ranges accordingly:
stats 'datafile' using 1:2 nooutput min = (STATS_min_y < STATS_min_x ? STATS_min_y : STATS_min_x) min = (STATS_max_y > STATS_max_x ? STATS_max_y : STATS_max_x) sc = 1.05 set xrange[sc*min:sc*max] set yrange[sc*min:sc*max] set size ratio -1 plot 'datafile'
source share