2.10 Setting Axis Ranges

In Section 2.2, the set xlabel configuration command was previously introduced for placing text labels on axes. In this section, the configuration of axes is extended to setting their ranges.

By default, PyXPlot automatically scales axes to some sensible range which contains all of the plotted data. However, it is possible for the user to override this and set his own range. This can be done directly from the plot command, for example:

plot [-1:1][-2:2] sin(x)

The ranges are specified immediately after the plot command, with the syntax [minimum:maximum].1 The first specified range applies to the $x$-axis, and the second to the $y$-axis.2 Any of the values can be omitted, for example:

plot [:][-2:2] sin(x)

would only set a range on the $y$-axis.

Alternatively, ranges can be set before the plot statement, using the set xrange command, for example:

set xrange [-2:2]
set y2range [a:b]

If an asterisk is supplied in place of either of the limits in this command, then any limit which had previously been set is switched off, and the axis returns to its default autoscaling behaviour:

set xrange [-2:*]

A similar effect may be obtained using the set autoscale command, which takes a list of the axes to which it is to apply. Both the upper and lower limits of these axes are set to scale automatically. If no list is supplied, then the command is applied to all axes.

set autoscale x y
set autoscale

Axes can be set to have logarithmic scales by using the set logscale command, which also takes a list of axes to which it should apply. Its converse is set nologscale:

set logscale
set nologscale y x x2

Further discussion of the configuration of axes can be found in Section 4.5.

Footnotes

  1. An alternative valid syntax is to replace the colon with the word to: [minimum to maximum].
  2. As will be discussed in Section 4.5, if further ranges are specified, they apply to the $x2$-axis, then the $y2$-axis, and so forth.