14

How can I limit the autoscaling of gnuplot, so that, as example for the y-max, it is at least a certain value and it would autoscale up to fixed "limit"?

From looking at the documentation, I only see how to fix min-, or max- end of the axis, while the other is being scaled automatically.

About autoscaling on PDF page 93

Thor
  • 45,082
  • 11
  • 119
  • 130
varesa
  • 2,399
  • 7
  • 26
  • 45
  • Could you clarify what you mean by autoscaling? Do you want to set the ymax to a certain value, or do you want to scale the data so that its maximum has a certain value? – andyras Jun 29 '12 at 23:10
  • @andyras Example for ymax: the minimum (of the ymax) could be 100, and maximum 1000. If the highest data point is 50, the ymax would be 100. It would scale automatically for values up to 1000. After that the values would be cut out. – varesa Jun 30 '12 at 05:48

4 Answers4

20

Since version 4.6 gnuplot offers a new syntax to specify upper and lower limits for the autoscaling. For your case you could use

set xrange [0:100 < * < 1000]

Quoting from the documentation:

The range in which autoscaling is being performed may be limited by a lower bound <lb> or an upper bound <ub> or both. The syntax is

{ <lb> < } * { < <ub> }

For example

0 < * < 200

sets <lb> = 0 and <ub> = 200.

That syntax can be applied to both the minimum or maximum value of set *range.

To autoscale xmin but keeping it positive, use

set xrange [0<*:]

To autoscale x but keep minimum range of 10 to 50:

set xrange [*<10:50<*]

See the documentation about set xrange for more information.

Christoph
  • 47,569
  • 8
  • 87
  • 187
5

I don't think it is possible, either you have autoscaling on no-, min- or max-, or both axis i.e.:

set yrange [FIXED_MIN : FIXED_MAX]
set yrange [        * : FIXED_MAX]
set yrange [FIXED_MIN :         *]
set yrange [        * :          ]

Respectively.

Thor
  • 45,082
  • 11
  • 119
  • 130
  • So it seems that it really was like that, rather that I not being able to find it. Seems I have to manually scale using the data – varesa Jun 30 '12 at 05:46
4

In this case, you could filter the data and let gnuplot do it's normal auto-scaling:

set yrange [*:*]
plot 'mydatafile' u 1:(($2 >= YMIN && $2 <= YMAX) ? $2 : 1/0)
mgilson
  • 300,191
  • 65
  • 633
  • 696
  • That is pretty much what I did(, but outside of gnuplot). Sorry if I read the code wrong, but that leaves out every value below YMIN? You might have slightly misinterpreted what I wanted (eg. Ymin=0, Ymax=100-1000). I solved this by adding a single point of data, with the background color (so it is invisible) at YMIN. That gave me the effect I wanted. – varesa Jun 30 '12 at 18:33
  • 1
    @varesa -- If you're using gnuplot 4.6, there's also the `stats` command which you could pair the the above filter and the gnuplot-defined variables: `GPVAL_YMIN` and `GPVAL_XMIN`, but now we're starting to get a little more complicated. the "invisible" point is an interesting idea however -- I like it. – mgilson Jun 30 '12 at 18:41
  • @mgilson Gnuplot 4.6 added even a new syntax for such upper and lower limits in autoscaling, like `set xrange [0:100 < * < 1000]`. – Christoph Dec 12 '13 at 11:19
1

Since people seem to be interested in this question, I'll add the way I solved this as an answer:

I made the minimum for the autoscaling by inserting a invisible marker in the beginning of the data. That cause the plot to always "show" it, even though it can not bee seen.

Then I implemented the maximum outside of gnuplot (propably could have been possible inside it as well, take a look at mgilson's answer), in a parser script that I have used to prepare the data for gnuplot.

Actually in the script I took all the "clipped out" values, added them to y=0, and made them red. That way I get a "warning", of values being too big to be sensible to graph. (My program monitors pings between two hosts, and there is no sense trying to graph 5s+ latencies => I mark it as connection broken)

varesa
  • 2,399
  • 7
  • 26
  • 45