On this page:
6.2.2Log Ticks
6.2.3Date Ticks
6.2.4Time Ticks
8.18
top
up

6Axis Transforms and TicksπŸ”— i

(require plot ) package: plot-gui-lib

6.1Axis TransformsπŸ”— i

The x, y and z axes for any plot can be independently transformed by parameterizing the plot on different plot-x-transform , plot-y-transform and plot-z-transform values. For example, to plot the x axis with a log transform:
Most log-transform ed plots use different ticks than the default, uniformly spaced ticks, however. To put log ticks on the x axis, set the plot-x-ticks parameter:
See Axis Ticks for more details on parameterizing a plot’s axis ticks.

To sample nonlinearly, the inverse of a transform is applied to linearly sampled points. See make-axis-transform and nonlinear-seq . Renderers cooperate with the current transforms by sampling nonlinearly. For example,
Notice that the surface is sampled uniformly in appearance even though the x-axis ticks are not spaced uniformly.

Transforms are applied to the primitive shapes that comprise a plot:
Here, the renderer returned by surface3d does not have to bend the polygons it draws; plot3d does this automatically (by recursive subdivision).

Independent, per-axis, monotone, nonlinear transforms. Plot comes with some typical (and some atypical) axis transforms, documented immediately below.

The identity axis transform, the default transform for all axes.

A log transform. Use this to generate plots with log-scale axes. Any such axis must have positive bounds.

The beginning of the Axis Transforms and Ticks section has a working example. An example of exceeding the bounds is

log-transform: expects type <positive real> as 1st argument, given: -1; other arguments were: 1

See axis-transform-bound and axis-transform-append for ways to get around an axis transform’s bounds limitations.

procedure

( stretch-transform abscale)axis-transform/c

a:real?
b:real?
scale:(>/c 0)
Returns an axis transform that stretches a finite interval.

The following example uses a stretch-transform to draw attention to the interval [-1,1] in an illustration of the limit of sin(x)/x as x approaches zero (a critical part of proving the derivative of sin(x)):
(plot (list (y-axis -1#:ticks?#f)(y-axis 1#:ticks?#f)
(function (λ (x)(/ (sin x)x))-1414
#:width2#:color4#:label"y = sin(x)/x")
(point-label (vector 01)"y → 1 as x → 0"
#:anchor'bottom-right))
#:y-max1.2))

Returns an axis transform that collapses a finite interval to its midpoint. For example, to remove part of the long, boring asymptotic approach of atan(x) toward π/2:
(plot (function atan 10200#:label"y = atan(x)")
#:legend-anchor'center))
In this case, there were already ticks at the collapsed interval’s endpoints. If there had not been, it would have been necessary to use ticks-add to let viewers know precisely the interval that was collapsed. (See stretch-transform for an example.)

A “cube-root” transform, mostly used for testing. Unlike the log transform, it is defined on the entire real line, making it better for testing the appearance of plots with nonlinearly transformed axes.

freq:(>/c 0)
An extremely important test case, which makes sure that Plot can use any monotone, invertible function as an axis transform. The freq parameter controls the “shakiness” of the transform. At high values, it makes plots look like Peanuts cartoons.

The contract for axis transforms.

The easiest ways to construct novel axis transforms are to use the axis transform combinators axis-transform-append , axis-transform-bound and axis-transform-compose , or to apply make-axis-transform to an invertible-function .

Returns an axis transform that transforms values less than mid like t1, and transforms values greater than mid like t2. (Whether it transforms mid like t1 or t2 is immaterial, as a transformed mid is equal to mid either way.)

Returns an axis transform that transforms values like t does in the interval [a,b], but like the identity transform outside of it. For example, to bound log-transform to an interval in which it is well-defined,

Composes two axis transforms. For example, to collapse part of a log-transform ed axis, try something like
Argument order matters, but predicting the effects of exchanging arguments can be difficult. Fortunately, the effects are usually slight.

Given a monotone invertible-function , returns an axis transform. Monotonicity is necessary, but cannot be enforced. The inverse is used to take samples uniformly along transformed axes (see nonlinear-seq ).

Example:

An axis transform created by make-axis-transform (or by any of the above combinators) does not transform the endpoints of an axis’s bounds, to within floating-point error. For example,
(define xs'(123))
(define new-xs(map fxs))
(define old-xs(map gnew-xs))
(values new-xsold-xs))

'(1.0 2.2618595071429146 3.0)

'(1.0 1.9999999999999998 3.0000000000000004)

Technically, fun does not need to be truly invertible. Given fun = (invertible-function fg), it is enough for f to be a left inverse of g; that is, always (f(gx))= x but not necessarily (g(fx))= x. If f and g had to be strict inverses of each other, there could be no collapse-transform .

procedure

( apply-axis-transform tx-minx-max)invertible-function?

x-min:real?
x-max:real?
Returns an invertible function that transforms axis points within the given axis bounds. This convenience function is used internally to transform points before rendering, but is provided for completeness.

6.2Axis TicksπŸ”— i

Each plot axis has two independent sets of ticks: the near ticks and the far ticks.

parameter

( plot-x-ticks )ticks?

(plot-x-ticks ticks)void?
ticks:ticks?

parameter

( plot-y-ticks )ticks?

(plot-y-ticks ticks)void?
ticks:ticks?

parameter

( plot-z-ticks )ticks?

(plot-z-ticks ticks)void?
ticks:ticks?

Example:
> (parameterize ([plot-x-label "Near x axis"]
[plot-y-label "Near y axis"]
[plot-z-label "Near z axis"]
[plot-x-far-label "Far x axis"]
[plot-y-far-label "Far y axis"]
[plot-z-far-label "Far z axis"]
(plot3d (lines3d '(#(111)#(4000000044))#:style'transparent)
#:angle45#:altitude50
#:title"Axis Names and Tick Locations"))

At any #:angle, the far x and y ticks are behind the plot, and the far z ticks are on the right. Far ticks are drawn, but not labeled, if they are identical to their corresponding near ticks. They are always identical by default.

Major ticks are longer than minor ticks. Major tick labels are always drawn unless collapsed with a nearby tick. Minor tick labels are never drawn.

Renderers produced by contours and contour-intervals use the value of plot-z-ticks to place and label contour lines. For example, compare plots of the same function rendered using both contour-intervals and contour-intervals3d :
(define (saddlexy)(- (sqr x)(sqr y)))
(plot (contour-intervals saddle-11-11#:label"z")
#:legend-anchor'center)
(plot3d (contour-intervals3d saddle-11-11#:label"z")
#:legend-anchor'center)))

procedure

( contour-ticks z-ticks
z-min
z-max
levels
intervals?)(listof tick? )
z-ticks:ticks?
z-min:real?
z-max:real?
intervals?:boolean?
Returns the ticks used for contour values. This is used internally by renderers returned from contours , contour-intervals , contours3d , contour-intervals3d , and isosurfaces3d , but is provided for completeness.

When levels is 'auto, the returned values do not correspond exactly with the values of ticks returned by z-ticks: they might be missing the endpoint values. For example,

'(0 1/5 2/5 3/5 4/5 1)

'(1/5 2/5 3/5 4/5)

parameter

( plot-d-ticks )ticks?

(plot-d-ticks ticks)void?
ticks:ticks?
The ticks used for default isosurface values in isosurfaces3d .

parameter

( plot-r-ticks )ticks?

(plot-r-ticks ticks)void?
ticks:ticks?
The ticks used for radius lines in polar-axes .

struct

(struct ticks (layoutformat)
#:extra-constructor-namemake-ticks)
A ticks for a near or far axis consists of a layout function, which determines the number of ticks and where they will be placed, and a format function, which determines the ticks’ labels.

procedure

( ticks-generate ticksminmax)(listof tick? )

ticks:ticks?
min:real?
max:real?
Generates the tick values for the range [min, max], with layout and format specified by ticks.

Example:

(list

(tick 7/20 #f ".35")

(tick 2/5 #t ".4")

(tick 9/20 #f ".45")

(tick 1/2 #t ".5")

(tick 11/20 #f ".55")

(tick 3/5 #t ".6")

(tick 13/20 #f ".65"))

Most tick layout functions (and thus their corresponding ticks -constructing functions) have a #:number keyword argument with default (ticks-default-number ). What the number means depends on the tick layout function. Most use it for an average number of major ticks.

It is unlikely to mean the exact number of major ticks. Without adjusting the number of ticks, layout functions usually cannot find uniformly spaced ticks that will have simple labels after formatting. For example, the following plot shows the actual number of major ticks for the interval [0,x] when the requested number of ticks is 8, as generated by linear-ticks-layout :
> (plot (function (λ (x)
((linear-ticks-layout #:number8)0x)))
0.110)
#:x-label"Interval [0,x]"#:y-label"Number of ticks")

6.2.1Linear TicksπŸ”— i

procedure

( linear-ticks-layout [ #:numbernumber
#:basebase
#:divisorsdivisors]
#:scientific?scientific?)
base:(and/c exact-integer? (>=/c 2))=10
divisors:(listof exact-positive-integer? )='(1245)
scientific?:#t

procedure

( linear-ticks-format #:scientific?scientific?)

scientific?:#t

procedure

( linear-ticks [ #:numbernumber
#:basebase
#:divisorsdivisors])ticks?
base:(and/c exact-integer? (>=/c 2))=10
divisors:(listof exact-positive-integer? )='(1245)
The layout function, format function, and combined ticks for uniformly spaced ticks.

To lay out ticks, linear-ticks-layout finds the power of base closest to the axis interval size, chooses a simple first tick, and then chooses a skip length using divisors that maximizes the number of ticks without exceeding number. For strategic use of non-default arguments, see bit/byte-ticks , currency-ticks , and fraction-ticks . The default arguments correspond to the standard 1-2-5-in-base-10 rule used almost everywhere in plot tick layout.

To format ticks, linear-ticks-format uses real->plot-label passing the value of scientific?, and uses digits-for-range to determine the maximum number of fractional digits in the decimal expansion.

Changed in version 1.1 of package plot-gui-lib: Added the #:scientific? argument to linear-ticks-format and linear-ticks .

6.2.2Log TicksπŸ”— i

procedure

( log-ticks-layout [ #:numbernumber
#:basebase])ticks-layout/c
base:(and/c exact-integer? (>=/c 2))=10

procedure

( log-ticks-format [ #:basebase]
#:scientific?scientific?)ticks-format/c
base:(and/c exact-integer? (>=/c 2))=10
scientific?:#t

procedure

( log-ticks [ #:numbernumber
#:basebase]
#:scientific?scientific?)ticks?
base:(and/c exact-integer? (>=/c 2))=10
scientific?:#t
The layout function, format function, and combined ticks for exponentially spaced major ticks. (The minor ticks between are uniformly spaced.) Use these ticks for log-transform ed axes, because when exponentially spaced tick positions are log-transform ed, they become uniformly spaced.

The #:base keyword argument is the logarithm base. The #:scientific keyword argument disables scientific formatting, similarly to linear-ticks . See plot-z-far-ticks for an example of use.

6.2.3Date TicksπŸ”— i

procedure

( date-ticks-format [#:formatsformats])ticks-format/c

procedure

( date-ticks [ #:numbernumber
#:formatsformats])ticks?
The layout function, format function, and combined ticks for uniformly spaced ticks with date labels.

These axis ticks regard values as being in seconds since a system-dependent Universal Coordinated Time (UTC) epoch. (For example, the Unix and Mac OS X epoch is January 1, 1970 UTC, and the Windows epoch is January 1, 1601 UTC.) Use date->seconds to convert local dates to seconds, or datetime->real to convert dates to UTC seconds in a way that accounts for time zone offsets.

Actually, date-ticks-layout does not always space ticks quite uniformly. For example, it rounds ticks that are spaced about one month apart or more to the nearest month. Generally, date-ticks-layout tries to place ticks at minute, hour, day, week, month and year boundaries, as well as common multiples such as 90 days or 6 months.

To try to avoid displaying overlapping labels, date-ticks-format chooses date formats from formats for which labels will contain no redundant information.

All the format specifiers given in srfi/19 (which are derived from Unix’s date command), except those that represent time zones, are allowed in date format strings.

The default date formats.

=
'("~Y-~m-~d ~H:~M:~f"
"~Y-~m-~d ~H:~M"
"~Y-~m-~d ~Hh"
"~Y-~m-~d"
"~Y-~m"
"~Y"
"~m-~d ~H:~M:~f"
"~m-~d ~H:~M"
"~m-~d ~Hh"
"~m-~d"
"~H:~M:~f"
"~H:~M"
"~Hh"
"~M:~fs"
"~Mm"
"~fs")
=
'("~Y-~m-~d ~I:~M:~f ~p"
"~Y-~m-~d ~I:~M ~p"
"~Y-~m-~d ~I ~p"
"~Y-~m-~d"
"~Y-~m"
"~Y"
"~m-~d ~I:~M:~f ~p"
"~m-~d ~I:~M ~p"
"~m-~d ~I ~p"
"~m-~d"
"~I:~M:~f ~p"
"~I:~M ~p"
"~I ~p"
"~M:~fs"
"~Mm"
"~fs")

6.2.4Time TicksπŸ”— i

procedure

( time-ticks-format [#:formatsformats])ticks-format/c

procedure

( time-ticks [ #:numbernumber
#:formatsformats])ticks?
The layout function, format function, and combined ticks for uniformly spaced ticks with time labels.

These axis ticks regard values as being in seconds. Use datetime->real to convert sql-time or plot-time values to seconds.

Generally, time-ticks-layout tries to place ticks at minute, hour and day boundaries, as well as common multiples such as 12 hours or 30 days.

To try to avoid displaying overlapping labels, time-ticks-format chooses a date format from formats for which labels will contain no redundant information.

All the time-related format specifiers given in srfi/19 (which are derived from Unix’s date command) are allowed in time format strings.

The default time formats.

=
'("~dd ~H:~M:~f"
"~dd ~H:~M"
"~dd ~Hh"
"~dd"
"~H:~M:~f"
"~H:~M"
"~Hh"
"~M:~fs"
"~Mm"
"~fs")
=
'("~dd ~I:~M:~f ~p"
"~dd ~I:~M ~p"
"~dd ~I ~p"
"~dd"
"~I:~M:~f ~p"
"~I:~M ~p"
"~I ~p"
"~M:~fs"
"~Mm"
"~fs")

6.2.5Currency TicksπŸ”— i

procedure

( currency-ticks-format [ #:kindkind
#:scalesscales
#:formatsformats])ticks-format/c
kind:(or/c string? symbol? )='USD

procedure

( currency-ticks [ #:numbernumber
#:kindkind
#:scalesscales
#:formatsformats])ticks?
kind:(or/c string? symbol? )='USD
The format function and combined ticks for uniformly spaced ticks with currency labels; currency-ticks uses linear-ticks-layout for layout.

The #:kind keyword argument is either a string containing the currency symbol, or a currency code such as 'USD, 'GBP or 'EUR. The currency-ticks-format function can map most ISO 4217 currency codes to their corresponding currency symbol.

The #:scales keyword argument is a list of suffixes for each 103 scale, such as "K" (US thousand, or kilo), "bn" (UK short-scale billion) or "Md" (EU long-scale milliard). Off-scale amounts are given power-of-ten suffixes such as “×1021.”

The #:formats keyword argument is a list of three format strings, representing the formats of positive, negative, and zero amounts, respectively. The format specifiers are:
  • "~$": replaced by the currency symbol

  • "~w": replaced by the whole part of the amount

  • "~f": replaced by the fractional part, with 2 or more decimal digits

  • "~s": replaced by the scale suffix

  • "~~": replaced by “~”

The default currency scales and formats.

For example, a Plot user in France would probably begin programs with
and use (currency-ticks #:kind'EUR) for local currency or (currency-ticks #:kind'JPY) for Japanese Yen.

Cultural sensitivity notwithstanding, when writing for a local audience, it is generally considered proper to use local currency scales and formats for foreign currencies, but use the foreign currency symbol.

value

us-currency-scales :(listof string? )='("""K""M""B""T")

Short-scale suffix abbreviations as commonly used in the United States, Canada, and some other English-speaking countries. These stand for “kilo,” “million,” “billion,” and “trillion.”

value

uk-currency-scales :(listof string? )='("""k""m""bn""tr")

Short-scale suffix abbreviations as commonly used in the United Kingdom since switching to the short scale in 1974, and as currently recommended by the Daily Telegraph and Times style guides.

value

eu-currency-scales :(listof string? )='("""K""M""Md""B")

European Union long-scale suffix abbreviations, which stand for “kilo,” “million,” “milliard,” and “billion.”

The abbreviations actually used vary with geography, even within countries, but these seem to be common. Further long-scale suffix abbreviations such as for “billiard” are omitted due to lack of even weak consensus.

='("~$~w.~f~s""(~$~w.~f~s)""~0ドル")
Common currency formats used in the United States.

='("~$~w.~f~s""-~$~w.~f~s""~0ドル")
Common currency formats used in the United Kingdom. Note that it sensibly uses a negative sign to denote negative amounts.

='("~w,~f ~s~$""-~w,~f ~s~$""0 ~$")
A guess at common currency formats for the European Union. Like scale suffixes, actual formats vary with geography, but currency formats can even vary with audience or tone.

6.2.6Other TicksπŸ”— i

The layout function, format function, and combined ticks for no ticks whatsoever.

procedure

( bit/byte-ticks-format [ #:sizesize
#:kindkind])ticks-format/c
size:(or/c 'byte'bit)='byte
kind:(or/c 'CS'SI)='CS

procedure

( bit/byte-ticks [ #:numbernumber
#:sizesize
#:kindkind])ticks?
size:(or/c 'byte'bit)='byte
kind:(or/c 'CS'SI)='CS
The format function and combined ticks for bit or byte values.

The #:kind keyword argument indicates either International System of Units ('SI) suffixes, as used to communicate hard drive capacities, or Computer Science ('CS) suffixes, as used to communicate memory capacities.

For layout, bit/byte-ticks uses linear-ticks-layout with
  • If kind is 'SI, base 10 and divisors '(1245).

  • If kind is 'CS, base 2 and divisors '(12).

procedure

( fraction-ticks-format [ #:basebase
#:divisorsdivisors])ticks-format/c
base:(and/c exact-integer? (>=/c 2))=10
divisors:(listof exact-positive-integer? )='(12345)

procedure

( fraction-ticks [ #:basebase
#:divisorsdivisors])ticks?
base:(and/c exact-integer? (>=/c 2))=10
divisors:(listof exact-positive-integer? )='(12345)
The format function and combined ticks for fraction-formatted values. For layout, fraction-ticks uses linear-ticks-layout , passing it the given divisors.

6.2.7Tick CombinatorsπŸ”— i

procedure

( ticks-mimic thunk)ticks?

thunk:(-> ticks? )
Returns a ticks that mimics the given ticks returned by thunk. Used in default values for plot-x-far-ticks , plot-y-far-ticks and plot-z-far-ticks to ensure that, unless one of these parameters is changed, the far tick labels are not drawn.

procedure

( ticks-add txs[major?])ticks?

t:ticks?
xs:(listof real? )
major?:boolean? =#t
Returns a new ticks that acts like t, except that it puts additional ticks at positions xs. If major? is true, the ticks at positions xs are all major ticks; otherwise, they are minor ticks.

procedure

( ticks-scale tfun)ticks?

t:ticks?
Returns a new ticks that acts like t, but for an axis transformed by fun. Unlike with typical Axis Transforms, fun is allowed to transform axis endpoints. (See make-axis-transform for an explanation about transforming endpoints.)

Use ticks-scale to plot values at multiple scales simultaneously, with one scale on the near axis and one scale on the far axis. The following example plots degrees Celsius on the left and degrees Fahrenheit on the right:
(linear-scale 9/532))]
[plot-y-label "Temperature (°C)"]
[plot-y-far-label "Temperature (°F)"])
(define data
(list #(00)#(150.6)#(309.5)#(4510.0)#(6016.6)
#(7541.6)#(9042.7)#(10565.5)#(12078.9)
#(13578.9)#(150131.1)#(165151.1)#(180176.2)))
(function (λ (x)(/ (sqr x)180))0180
#:style'long-dash#:color3#:label"Trend")
(lines data#:color2#:width2)
(points data#:color1#:line-width2#:label"Measured"))
#:y-min-25#:x-label"Time"))

6.2.8Tick Data Types and ContractsπŸ”— i

struct

(struct pre-tick (valuemajor?)
#:extra-constructor-namemake-pre-tick)
value:real?
major?:boolean?
Represents a tick that has not yet been labeled.

struct

(struct tick pre-tick (label)
#:extra-constructor-namemake-tick)
label:string?
Represents a tick with a label.

The contract for tick layout functions in ticks structures. The function receives axis bounds and returns a list of pre-tick s to be shown on the axis.

Note that the layout function returns pre-tick s, or unlabeled ticks, and a separate format function is used to produce the labels for the ticks.

The contract for tick format functions in ticks structures. The format function receives axis bounds and a list of pre-tick s. It must return a label for each pre-tick in this list.

The returned labels should be usually distinct, as the plot library will consider ticks with labels that are string=? to be duplicates and collapse them, however, this feature can be used by a custom format function to force removal of some ticks from the plot.

Axis bounds can be used to determine how many decimal digits to display, usually by applying digits-for-range to the bounds.

6.3Invertible FunctionsπŸ”— i

#:extra-constructor-namemake-invertible-function)
f:(-> real? real? )
g:(-> real? real? )
Represents an invertible function. Used for Axis Transforms and by ticks-scale .

The function itself is f, and its inverse is g. Because real? s can be inexact, this invariant must be approximate and therefore cannot be enforced. (For example, (exp (log 10)) = 10.000000000000002.) The obligation to maintain it rests on whomever constructs one.

The identity function as an invertible-function .

Returns the composition of two invertible functions.

Returns the inverse of an invertible function.

Returns a one-dimensional linear scaling function, as an invertible-function . This function constructs the most common arguments to ticks-scale .

top
up

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /