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:
Neil Toronto 2012-11-25 23:28:54 -07:00
parent 49a0b950b7
commit 8aa623c2e8
7 changed files with 32 additions and 12 deletions

View File

@ -33,6 +33,6 @@
(define eval (make-base-eval))
(eval '(require math))
(eval '(require (rename-in (except-in plot plot plot3d)
[plot-bitmap plot]
[plot3d-bitmap plot3d])))
[plot-pict plot]
[plot3d-pict plot3d])))
eval)

View File

@ -28,6 +28,8 @@
[(zero? num) empty]
; ambiguous request: arbitrarily return 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
(define size (- end start))
(define step (/ size (cond [(and start? end?) (- num 1)]

View File

@ -34,8 +34,8 @@
(eval '(begin
(require racket/math racket/match racket/list racket/draw racket/class
(rename-in (except-in plot plot plot3d)
[plot-bitmap plot]
[plot3d-bitmap plot3d])
[plot-pict plot]
[plot3d-pict plot3d])
plot/utils)))
eval))

View File

@ -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:
@interaction[#:eval plot-eval
(eval:alts
(plot (function sqr))
(eval:result "" "" "plot: could not determine sensible plot bounds; got x ∈ [#f,#f], y ∈ [#f,#f]"))
(eval:alts
(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)))]
(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.
We might say that bounds passed to renderers are @italic{suggestions}, and bounds passed to @(racket plot) and @(racket plot3d) are @italic{commandments}.

View File

@ -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
@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

View File

@ -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
@interaction[#:eval plot-eval
(eval:alts
(parameterize ([plot-x-transform log-transform])
(plot (function (λ (x) x) -1 1)))]
(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.
}

View File

@ -17,10 +17,15 @@
int-str->e-str frac-str->e-str)
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? #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? #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?
(λ () (vector-field (λ (v [z 0]) v) -4 4 -4 4))