Made plots in plot' and
math' render nicely in PDFs (plots in docs are picts now)
Fixed errors in `linear-seq' when end <= start
This commit is contained in:
parent
49a0b950b7
commit
8aa623c2e8
|
@ -33,6 +33,6 @@
|
||||||
(define eval (make-base-eval))
|
(define eval (make-base-eval))
|
||||||
(eval '(require math))
|
(eval '(require math))
|
||||||
(eval '(require (rename-in (except-in plot plot plot3d)
|
(eval '(require (rename-in (except-in plot plot plot3d)
|
||||||
[plot-bitmap plot]
|
[plot-pict plot]
|
||||||
[plot3d-bitmap plot3d])))
|
[plot3d-pict plot3d])))
|
||||||
eval)
|
eval)
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
[(zero? num) empty]
|
[(zero? num) empty]
|
||||||
; ambiguous request: arbitrarily return start
|
; ambiguous request: arbitrarily return start
|
||||||
[(and start? end? (= 1 num)) (list start)]
|
[(and start? end? (= 1 num)) (list start)]
|
||||||
|
[(end . < . start) (reverse (linear-seq end start num #:start? end? #:end? start?))]
|
||||||
|
[(end . = . start) (build-list num (λ _ start))]
|
||||||
[else
|
[else
|
||||||
(define size (- end start))
|
(define size (- end start))
|
||||||
(define step (/ size (cond [(and start? end?) (- num 1)]
|
(define step (/ size (cond [(and start? end?) (- num 1)]
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
(eval '(begin
|
(eval '(begin
|
||||||
(require racket/math racket/match racket/list racket/draw racket/class
|
(require racket/math racket/match racket/list racket/draw racket/class
|
||||||
(rename-in (except-in plot plot plot3d)
|
(rename-in (except-in plot plot plot3d)
|
||||||
[plot-bitmap plot]
|
[plot-pict plot]
|
||||||
[plot3d-bitmap plot3d])
|
[plot3d-pict plot3d])
|
||||||
plot/utils)))
|
plot/utils)))
|
||||||
eval))
|
eval))
|
||||||
|
|
||||||
|
|
|
@ -108,11 +108,19 @@ In both cases, @(racket plot) and @(racket function-interval) work together to d
|
||||||
It is not always possible for renderers and @(racket plot) or @(racket plot3d) to determine the bounds:
|
It is not always possible for renderers and @(racket plot) or @(racket plot3d) to determine the bounds:
|
||||||
|
|
||||||
@interaction[#:eval plot-eval
|
@interaction[#:eval plot-eval
|
||||||
(plot (function sqr))
|
(eval:alts
|
||||||
(plot (function sqr #f #f))
|
(plot (function sqr))
|
||||||
(plot (function sqr (- pi)))
|
(eval:result "" "" "plot: could not determine sensible plot bounds; got x ∈ [#f,#f], y ∈ [#f,#f]"))
|
||||||
(plot (list (function sqr #f 0)
|
(eval:alts
|
||||||
(function sqr 0 #f)))]
|
(plot (function sqr #f #f))
|
||||||
|
(eval:result "" "" "plot: could not determine sensible plot bounds; got x ∈ [#f,#f], y ∈ [#f,#f]"))
|
||||||
|
(eval:alts
|
||||||
|
(plot (function sqr (- pi)))
|
||||||
|
(eval:result "" "" "plot: could not determine sensible plot bounds; got x ∈ [-3.141592653589793,#f], y ∈ [#f,#f]"))
|
||||||
|
(eval:alts
|
||||||
|
(plot (list (function sqr #f 0)
|
||||||
|
(function sqr 0 #f)))
|
||||||
|
(eval:result "" "" "plot: could not determine sensible plot bounds; got x ∈ [0,0], y ∈ [0,0]"))]
|
||||||
|
|
||||||
There is a difference between passing bounds to renderers and passing bounds to @(racket plot) or @(racket plot3d): bounds passed to @(racket plot) or @(racket plot3d) cannot be changed by a renderer that requests different bounds.
|
There is a difference between passing bounds to renderers and passing bounds to @(racket plot) or @(racket plot3d): bounds passed to @(racket plot) or @(racket plot3d) cannot be changed by a renderer that requests different bounds.
|
||||||
We might say that bounds passed to renderers are @italic{suggestions}, and bounds passed to @(racket plot) and @(racket plot3d) are @italic{commandments}.
|
We might say that bounds passed to renderers are @italic{suggestions}, and bounds passed to @(racket plot) and @(racket plot3d) are @italic{commandments}.
|
||||||
|
|
|
@ -52,7 +52,10 @@ The safest way to ensure that @(racket plot) can determine bounds for the plot a
|
||||||
|
|
||||||
Because PLoT is now smarter about choosing bounds, there are better ways. For example, suppose you have
|
Because PLoT is now smarter about choosing bounds, there are better ways. For example, suppose you have
|
||||||
|
|
||||||
@interaction[#:eval plot-eval (plot (line sin))]
|
@interaction[#:eval plot-eval
|
||||||
|
(eval:alts
|
||||||
|
(plot (line sin))
|
||||||
|
(eval:result "" "" "plot: could not determine sensible plot bounds; got x ∈ [#f,#f], y ∈ [#f,#f]"))]
|
||||||
|
|
||||||
You could either change it to
|
You could either change it to
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,10 @@ A log transform. Use this to generate plots with log-scale axes. Any such axis m
|
||||||
|
|
||||||
The beginning of the @secref["ticks and transforms"] section has a working example. An example of exceeding the bounds is
|
The beginning of the @secref["ticks and transforms"] section has a working example. An example of exceeding the bounds is
|
||||||
@interaction[#:eval plot-eval
|
@interaction[#:eval plot-eval
|
||||||
(parameterize ([plot-x-transform log-transform])
|
(eval:alts
|
||||||
(plot (function (λ (x) x) -1 1)))]
|
(parameterize ([plot-x-transform log-transform])
|
||||||
|
(plot (function (λ (x) x) -1 1)))
|
||||||
|
(eval:result "" "" "log-transform: expects type <positive real> as 1st argument, given: -1; other arguments were: 1"))]
|
||||||
See @racket[axis-transform-bound] and @racket[axis-transform-append] for ways to get around an axis transform's bounds limitations.
|
See @racket[axis-transform-bound] and @racket[axis-transform-append] for ways to get around an axis transform's bounds limitations.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,15 @@
|
||||||
int-str->e-str frac-str->e-str)
|
int-str->e-str frac-str->e-str)
|
||||||
plot/common/worker-thread)
|
plot/common/worker-thread)
|
||||||
|
|
||||||
|
(check-equal? (linear-seq 1 1 2) '(1 1))
|
||||||
(check-equal? (linear-seq 0 1 2 #:start? #t #:end? #t) '(0 1))
|
(check-equal? (linear-seq 0 1 2 #:start? #t #:end? #t) '(0 1))
|
||||||
(check-equal? (linear-seq 0 1 2 #:start? #t #:end? #f) '(0 2/3))
|
(check-equal? (linear-seq 0 1 2 #:start? #t #:end? #f) '(0 2/3))
|
||||||
(check-equal? (linear-seq 0 1 2 #:start? #f #:end? #t) '(1/3 1))
|
(check-equal? (linear-seq 0 1 2 #:start? #f #:end? #t) '(1/3 1))
|
||||||
(check-equal? (linear-seq 0 1 2 #:start? #f #:end? #f) '(1/4 3/4))
|
(check-equal? (linear-seq 0 1 2 #:start? #f #:end? #f) '(1/4 3/4))
|
||||||
|
(check-equal? (linear-seq 1 0 2 #:start? #t #:end? #t) '(1 0))
|
||||||
|
(check-equal? (linear-seq 1 0 2 #:start? #t #:end? #f) '(1 1/3))
|
||||||
|
(check-equal? (linear-seq 1 0 2 #:start? #f #:end? #t) '(2/3 0))
|
||||||
|
(check-equal? (linear-seq 1 0 2 #:start? #f #:end? #f) '(3/4 1/4))
|
||||||
|
|
||||||
(check-exn exn:fail:contract?
|
(check-exn exn:fail:contract?
|
||||||
(λ () (vector-field (λ (v [z 0]) v) -4 4 -4 4))
|
(λ () (vector-field (λ (v [z 0]) v) -4 4 -4 4))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user