GNUplot Autoscale sets xrange to yrange

I use GNUplot to build orbits from a data file. I want to use autoscale xy so that the GNUplot script does not need to be edited depending on the data. However, when I draw, autoscale does not set xrange to be the same as yrange . This makes the orbits look β€œcrushed”.

I tried using set size square and set size ratio -1 How to set equal scale length in gnuplot .

But that did not work.

Is there a way to get autoscale to make the x and y ranges equal?

Thanks!

+5
source share
1 answer

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' 
+5
source

Source: https://habr.com/ru/post/1207128/


All Articles