Search code examples
gnuplotaxismedian

GNUPLOT - How to set median value of data in the center of axis?


These are my data:

27941
34464
27308
33065
33754
29531
29106
31538
28100
23315
25601
29194
22322
20034
16368
17208
17963
16575
16825
19722

Median value is 26455, how to set it in the center of axis? I need to have min and max values still on axis, so shifting axis range is not the right solution. Thanks!


Solution

  • stats 'test' nooutput
    max(a,b)=(a>b)?a:b
    extent = max(STATS_max-STATS_median, STATS_median-STATS_min)
    set xrange[STATS_median-extent : STATS_median+extent]
    

    This will find the difference between max and median, then the difference between min and median, then the maximum of these two differences which I call extent. Then if we set xrange to median-extent : median+extent the center would be at the median and both the min and the max would be visible.

    If you also want some extra free space around min and max you could use extent = 1.1*max(STATS_max-STATS_median, STATS_median-STATS_min)