Axis

The axis() function controls the behavior of the x-axis and y-axis ranges. If you do not supply a parameter to axis(), the return value is a tuple in the form (xmin, xmax, ymin, ymax).You can use axis() to set the new axis ranges by specifying new values: axis([xmin, xmax, ymin, ymax]). In the special case you'd like to set or retrieve only the x-axis values or y-axis values, use the functions xlim(xmin, xmax) or ylim(ymin, ymax), respectively.

Other than the range limits, the function axis() also accepts the following values: 'auto', 'equal', 'tight', 'scaled', and 'off'. The value 'auto', the default behavior, allows plot() to select what it thinks are the best values. The value 'equal' forces each x value to be the same length as each y value, which is important if you're trying to convey physical distances, say, in a GPS plot. The value 'tight' causes the axis to change so that the maximum and minimum values of x and y both touch the edges of the graph. The value 'scaled' changes the x-axis and y-axis ranges so that x and y have both the same length (i.e., aspect ratio of 1). Lastly, calling axis('off') removes the axis and labels.

To illustrate these axis behaviors, I've plot a circle, as demonstrated in Listing 6-3.

Listing 6-3. Plotting a Circle R = 1.2

■ Note The reason I chose a circle of radius 1.2 is that in the case of a radius of "nicer" numbers (say 1.0 or 2.0), the automatic axis solution works very well, and it's hard to show the effects of the different axis options.

Figure 6-4 shows the results of applying different axis values to this circle.

Figure 6-4. Controlling axis behavior

Figure 6-4. Controlling axis behavior

Was this article helpful?

0 0

Post a comment