File: compat.scrbl

package info (click to toggle)
racket 7.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 125,432 kB
  • sloc: ansic: 258,980; pascal: 59,975; sh: 33,650; asm: 13,558; lisp: 7,124; makefile: 3,329; cpp: 2,889; exp: 499; python: 274; xml: 11
file content (195 lines) | stat: -rw-r--r-- 8,741 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#lang scribble/manual

@(require (for-label racket
                     racket/gui/base
                     plot/compat))

@title[#:tag "compat"]{Compatibility Module}

@author["Alexander Friedman" "Jamie Raymond" "Neil Toronto"]

@defmodule[plot/compat]

This module provides an interface compatible with Plot 5.1.3 and earlier.

@bold{Do not use this module in new programs.}
It is likely to disappear in a near future release.

@bold{Do not try to use both @racketmodname[plot] and @racketmodname[plot/compat] in the same program.}
The new features in Plot 5.2 and later require the objects plotted in @racketmodname[plot] have to be a different data type than the objects plotted in @racketmodname[plot/compat].
They do not coexist easily, and trying to make them do so will result in errors.

@; ----------------------------------------

@section[#:tag "plot"]{Plotting}

@defproc[(plot [data (-> (is-a?/c 2d-plot-area%) void?)]
               [#:width width real? 400] [#:height height real? 400]
               [#:x-min x-min real? -5] [#:x-max x-max real? 5]
               [#:y-min y-min real? -5] [#:y-max y-max real? 5]
               [#:x-label x-label string? "X axis"] [#:y-label y-label string? "Y axis"]
               [#:title title string? ""]
               [#:fgcolor fgcolor (list/c byte? byte? byte?) '(0 0 0)]
               [#:bgcolor bgcolor (list/c byte? byte? byte?) '(255 255 255)]
               [#:lncolor lncolor (list/c byte? byte? byte?) '(255 0 0)]
               [#:out-file out-file (or/c path-string? output-port? #f) #f]
               ) (is-a?/c image-snip%)]{
Plots @racket[data] in 2D, where @racket[data] is generated by
functions like @racket[points] or @racket[line].

A @racket[data] value is represented as a procedure that takes a
@racket[2d-plot-area%] instance and adds plot information to it.

The result is an @racket[image-snip%] for the plot. If an @racket[#:out-file]
path or port is provided, the plot is also written as a PNG image to
the given path or port.

The @racket[#:lncolor] keyword argument is accepted for backward compatibility, but does nothing.
}

@defproc[(plot3d [data (-> (is-a?/c 3d-plot-area%) void?)]
                 [#:width width real? 400] [#:height height real? 400]
                 [#:x-min x-min real? -5] [#:x-max x-max real? 5]
                 [#:y-min y-min real? -5] [#:y-max y-max real? 5]
                 [#:z-min z-min real? -5] [#:z-max z-max real? 5]
                 [#:alt alt real? 30]
                 [#:az az real? 45]
                 [#:x-label x-label string? "X axis"]
                 [#:y-label y-label string? "Y axis"]
                 [#:z-label z-label string? "Z axis"]
                 [#:title title string? ""]
                 [#:fgcolor fgcolor (list/c byte? byte? byte?) '(0 0 0)]
                 [#:bgcolor bgcolor (list/c byte? byte? byte?) '(255 255 255)]
                 [#:lncolor lncolor (list/c byte? byte? byte?) '(255 0 0)]
                 [#:out-file out-file (or/c path-string? output-port? #f) #f]
                 ) (is-a?/c image-snip%)]{
Plots @racket[data] in 3D, where @racket[data] is generated by a
function like @racket[surface]. The arguments @racket[alt] and
@racket[az] set the viewing altitude (in degrees) and the azimuth
(also in degrees), respectively.

A 3D @racket[data] value is represented as a procedure that takes a
@racket[3d-plot-area%] instance and adds plot information to it.

The @racket[#:lncolor] keyword argument is accepted for backward compatibility, but does nothing.
}

@defproc[(points [vecs (listof (vectorof real?))]
                 [#:sym sym (or/c char? string? exact-integer? symbol?) 'square]
                 [#:color color plot-color? 'black]
                 ) (-> (is-a?/c 2d-plot-area%) void?)]{
Creates 2D plot data (to be provided to @racket[plot]) given a list
of points specifying locations. The @racket[sym] argument determines
the appearance of the points.  It can be a symbol, an ASCII character,
or a small integer (between -1 and 127).  The following symbols are
known: @racket['pixel], @racket['dot], @racket['plus],
@racket['asterisk], @racket['circle], @racket['times],
@racket['square], @racket['triangle], @racket['oplus], @racket['odot],
@racket['diamond], @racket['5star], @racket['6star],
@racket['fullsquare], @racket['bullet], @racket['full5star],
@racket['circle1], @racket['circle2], @racket['circle3],
@racket['circle4], @racket['circle5], @racket['circle6],
@racket['circle7], @racket['circle8], @racket['leftarrow],
@racket['rightarrow], @racket['uparrow], @racket['downarrow].
}

@defproc[(line [f (-> real? (or/c real? (vector/c real? real?)))]
               [#:samples samples (and/c exact-integer? (>=/c 2)) 150]
               [#:width width (>=/c 0) 1]
               [#:color color plot-color/c 'red]
               [#:mode mode (one-of/c 'standard 'parametric) 'standard]
               [#:mapping mapping (one-of/c 'cartesian 'polar) 'cartesian]
               [#:t-min t-min real? -5] [#:t-max t-max real? 5]
               ) (-> (is-a?/c 2d-plot-area%) void?)]{
Creates 2D plot data to draw a line.

The line is specified in either functional, i.e. @math{y = f(x)}, or
parametric, i.e. @math{x,y = f(t)}, mode.  If the function is
parametric, the @racket[mode] argument must be set to
@racket['parametric].  The @racket[t-min] and @racket[t-max] arguments
set the parameter when in parametric mode.
}

@defproc[(error-bars [vecs (listof (vector/c real? real? real?))]
                     [#:color color plot-color? 'black]
                     ) (-> (is-a?/c 2d-plot-area%) void?)]{
Creates 2D plot data for error bars given a list of vectors.  Each
vector specifies the center of the error bar @math{(x,y)} as the first
two elements and its magnitude as the third.
}

@defproc[(vector-field [f (-> (vector/c real? real?) (vector/c real? real?))]
                       [#:samples samples (and/c exact-integer? (>=/c 2)) 20]
                       [#:width width exact-positive-integer? 1]
                       [#:color color plot-color? 'red]
                       [#:style style (one-of/c 'scaled 'normalized 'real) 'scaled]
                       ) (-> (is-a?/c 2d-plot-area%) void?)]{
Creates 2D plot data to draw a vector-field from a vector-valued
function.
}

@defproc[(contour [f (-> real? real? real?)]
                  [#:samples samples exact-nonnegative-integer? 50]
                  [#:width width (>=/c 0) 1]
                  [#:color color plot-color/c 'black]
                  [#:levels levels (or/c (and/c exact-integer? (>=/c 2)) (listof real?)) 10]
                  ) (-> (is-a?/c 2d-plot-area%) void?)]{
Creates 2D plot data to draw contour lines, rendering a 3D function
a 2D graph cotours (respectively) to represent the value of the
function at that position.
}

@defproc[(shade [f (-> real? real? real?)]
                [#:samples samples (and/c exact-integer? (>=/c 2)) 50]
                [#:levels levels (or/c (and/c exact-integer? (>=/c 2)) (listof real?)) 10]
                ) (-> (is-a?/c 2d-plot-area%) void?)]{
Creates 2D plot data to draw like @racket[contour], except using
shading instead of contour lines.
}

@defproc[(surface [f (-> real? real? real?)]
                  [#:samples samples (and/c exact-integer? (>=/c 2)) 50]
                  [#:width width (>=/c 0) 1]
                  [#:color color plot-color/c 'black]
                  ) (-> (is-a?/c 3d-plot-area%) void?)]{
Creates 3D plot data to draw a 3D surface in a 2D box, showing only
the @italic{top} of the surface.
}

@defproc[(mix [data (-> any/c void?)] ...) (-> any/c void?)]{
Creates a procedure that calls each @racket[data] on its argument in
order. Thus, this function can composes multiple plot @racket[data]s
into a single data.
}

@defproc[(plot-color? [v any/c]) boolean?]{
Returns @racket[#t] if @racket[v] is one of the following symbols,
@racket[#f] otherwise:

@racketblock[
'white 'black 'yellow 'green 'aqua 'pink
'wheat 'grey 'blown 'blue 'violet 'cyan
'turquoise 'magenta 'salmon 'red
]
}

@; ----------------------------------------

@section{Miscellaneous Functions}

@defproc[(derivative [f (-> real? real?)] [h real? .000001]) (-> real? real?)]{
Creates a function that evaluates the numeric derivative of
@racket[f].  The given @racket[h] is the divisor used in the
calculation.
}

@defproc[(gradient [f (-> real? real? real?)] [h real? .000001])
         (-> (vector/c real? real?) (vector/c real? real?))]{
Creates a vector-valued function that computes the numeric gradient of
@racket[f].
}

@defproc[(make-vec [fx (-> real? real? real?)] [fy (-> real? real? real?)])
         (-> (vector/c real? real?) (vector/c real? real?))]{
Creates a vector-valued function from two parts.
}