From eb39b34a3b70615990d67962b6aeeb857446ab77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Axel=20S=C3=B8gaard?= Date: Mon, 2 Jul 2012 17:49:11 +0200 Subject: [PATCH] Plot now supports the option Axes. --- bracket/bracket.rkt | 14 ++++++++++---- plotting/adaptive-plotting.rkt | 23 +++++++++++++++-------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/bracket/bracket.rkt b/bracket/bracket.rkt index 9990ebb41..a4cbd9379 100644 --- a/bracket/bracket.rkt +++ b/bracket/bracket.rkt @@ -830,7 +830,10 @@ List->Set Define Range - Plot) + Plot + ; Plot options: + Axes + ) ;;; ;;; INVARIANT @@ -1182,6 +1185,8 @@ ; TODO: Improve this (eval u ns)) + ; Plot options: + (define Axes 'Axes) (define (Plot f range [options '(List)]) ; TODO: Implement options ;(displayln (list f range)) @@ -1190,18 +1195,19 @@ (define excluded? #f) ; TODO: plot2d needs to be extended to multiple functions #;(define fs - (match functions + (match functions [(List: f ...) f] [f (list f)] [else (error 'Plot "TODO")])) (define fs (list f)) + (define axes? (Member? Axes options)) (match range [(List: var x-min x-max) ; TODO: Declare var as a local variable ? (plot2d (if (procedure? f) - (λ (x) (f x)) + (λ (x) (f x)) (λ (x) (N (Substitute f (Equal var x))))) - x-min x-max y-min y-max excluded?)] + x-min x-max y-min y-max excluded? axes?)] [else (error)])) #;(and (real? x-min) (real? x-max) (real? y-min) (real? y-max) diff --git a/plotting/adaptive-plotting.rkt b/plotting/adaptive-plotting.rkt index 72426e22f..e4798a4e6 100644 --- a/plotting/adaptive-plotting.rkt +++ b/plotting/adaptive-plotting.rkt @@ -144,7 +144,10 @@ (loop more (list x2) (cons (reverse (cons x1 ys)) xss)) (loop (cons x2 more) (cons x1 ys) xss))]))) -(define (plot2d unwrapped-f [x-min -5] [x-max 5] [y-min -5] [y-max 5] [excluded? #f]) +(define (cons-if bool x xs) + (if bool (cons x xs) xs)) + +(define (plot2d unwrapped-f [x-min -5] [x-max 5] [y-min -5] [y-max 5] [excluded? #f] [axes? #t]) ; wrap the function to be drawn, s.t. it ; returns #f in error situations (define (excluded-from-domain? x) @@ -191,13 +194,15 @@ ; for visual comparision. (if *debug* - (begin + (begin (displayln (list (begin0 - (plot (list (map lines - (map remove-non-numbers - connected-points))) + (plot (list + (cons-if axes? (axes) + (map lines + (map remove-non-numbers + connected-points)))) #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max) (displayln (format "adaptive number of evaluations: ~a" count)) @@ -209,9 +214,11 @@ (reset-count)) - (plot (list (map lines - (map remove-non-numbers - connected-points))) + (plot (list + (cons-if axes? (axes) + (map lines + (map remove-non-numbers + connected-points)))) #:x-min x-min #:x-max x-max #:y-min y-min #:y-max y-max)))