Skip to content

@RayRacine /gist:3317104
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
TRing Hist* in Plot
#lang typed/racket/base
(require
(only-in racket/math
sqr)
(only-in typed/mred/mred
Snip%
Color%))
;; Use of mred/mred/Snip% fails :(
(define-type Image-Snip% Any)
(define-type Format
(U 'auto 'png 'jpeg
'xmb 'xpm 'bmp
'ps 'pdf 'svg))
(define-type Anchor
(U 'top-left 'top 'top-right
'left 'center 'right
'bottom-left 'bottom 'bottom-right))
(define-type Labels
(U (Listof (Option String))
((Listof Any) -> (Listof (Option String)))))
(define-type Alphas
(U (Listof Real)
((Listof Any) -> (Listof Real))))
(define-type Plot-Brush-Style
(U Integer 'transparent 'solid
'bdiagonal-hatch 'fdiagonal-hatch 'crossdiag-hatch
'horizontal-hatch 'vertical-hatch 'cross-hatch))
(define-type Plot-Brush-Styles
(U (Listof Plot-Pen-Style)
((Listof Any) -> (Listof Plot-Pen-Style))))
(define-type Plot-Pen-Style
(U Integer 'transparent 'solid
'bdiagnol-hatch 'fdiagonal-hatch
'horizontal-hath 'veritcal-hatch
'crossdisg-hatch 'cross-hatch))
(define-type Plot-Pen-Styles
(U (Listof Plot-Pen-Style)
((Listof Any) -> (Listof Plot-Pen-Style))))
(define-type Pen-Widths (U (Listof Plot-Pen-Style)
((Listof Any) -> (Listof Plot-Pen-Style))))
(define-type Plot-Color (U Integer (List Real Real Real)
String Symbol Color%))
(define-type Plot-Colors (U (Listof Plot-Color)
((Listof Any) -> (Listof Plot-Color))))
(define-type Discrete-Histogram-Data (Listof (Vector Any (Option (U Real Interval)))))
(define-type Stacked-Histogram-Data (Listof (Vector Any (Listof Real))))
(require/typed plot/utils
[opaque Renderer2d renderer2d?]
[opaque Nonrenderer nonrenderer?]
[linear-seq (Real Real Exact-Nonnegative-Integer -> (Listof Real))])
(define-type Renderer-Tree (Rec RTree (U (U Renderer2d Nonrenderer) (Listof RTree))))
(require/typed plot/main
[opaque Interval ivl?]
[ivl (Real Real -> Interval)]
[plot (Renderer-Tree
[#:x-min (Option Exact-Rational)]
[#:x-max (Option Exact-Rational)]
[#:y-min (Option Exact-Rational)]
[#:y-max (Option Exact-Rational)]
[#:width Natural]
[#:height Natural]
[#:title (Option String)]
[#:x-label (Option String)]
[#:y-label (Option String)]
[#:legend-anchor Anchor]
[#:out-file (Option (U Path Output-Port))]
[#:out-kind Format]
-> (U Image-Snip% Void))]
[rectangles ((Listof (Vector Interval Interval))
[#:x-min (Option Exact-Rational)]
[#:x-max (Option Exact-Rational)]
[#:y-min (Option Exact-Rational)]
[#:y-max (Option Exact-Rational)]
[#:color Plot-Color]
[#:style Plot-Brush-Style]
[#:line-color Plot-Color]
[#:line-width Plot-Brush-Style]
[#:line-style Plot-Pen-Style]
[#:alpha Real]
[#:label (Option String)]
-> Renderer2d)]
;; TR does not support KW and optional args.
[function ((Real -> Real)
(Option Exact-Rational)
(Option Exact-Rational)
[#:y-min Exact-Rational]
[#:y-max Exact-Rational]
[#:samples Integer]
[#:color Plot-Color]
[#:width Real]
[#:style Plot-Pen-Style]
[#:alpha Real]
[#:label (Option String)]
-> Renderer2d)]
[area-histogram ((Real -> Real)
(Listof Real)
[#:x-min (Option Exact-Rational)]
[#:x-max (Option Exact-Rational)]
[#:y-min (Option Exact-Rational)]
[#:y-max (Option Exact-Rational)]
[#:samples Integer]
[#:color Plot-Color]
[#:style Plot-Brush-Style]
[#:line-color Plot-Color]
[#:line-width Plot-Brush-Style]
[#:line-style Plot-Pen-Style]
[#:alpha Real]
[#:label (Option String)]
-> Renderer2d)]
[discrete-histogram (Discrete-Histogram-Data
[#:x-min (Option Exact-Rational)]
[#:x-max (Option Exact-Rational)]
[#:y-min (Option Exact-Rational)]
[#:y-max (Option Exact-Rational)]
[#:gap Real]
[#:skip Real]
[#:invert? Boolean]
[#:color Plot-Color]
[#:style Plot-Brush-Style]
[#:line-color Plot-Color]
[#:line-width Plot-Brush-Style]
[#:line-style Plot-Pen-Style]
[#:alpha Real]
[#:label (Option String)]
[#:add-ticks? Boolean]
[#:far-ticks? Boolean]
-> Renderer2d)]
[stacked-histogram (Stacked-Histogram-Data
[#:x-min (Option Exact-Rational)]
[#:x-max (Option Exact-Rational)]
[#:y-min (Option Exact-Rational)]
[#:y-max (Option Exact-Rational)]
[#:gap Real]
[#:skip Real]
[#:invert? Boolean]
[#:colors Plot-Colors]
[#:styles Plot-Brush-Styles]
[#:line-colors Plot-Colors]
[#:line-widths Pen-Widths]
[#:line-styles Plot-Pen-Styles]
[#:alphas (U Alphas Natural)]
[#:labels (U Labels Natural)]
[#:add-ticks? Boolean]
[#:far-ticks? Boolean]
-> (Listof Renderer2d))])
(define (test)
(: f (Real -> Real))
(define (f x) (exp (* -1/2 (sqr x))))
(plot (list (area-histogram f (linear-seq -4 4 10)
#:label "Root 2")
(function f -4 4))))
(define (test2)
(let: ((data : Discrete-Histogram-Data
(list #(A 1) #(B 2) #(B 3)
(vector 'C (ivl 0.5 1.5)))))
(plot (discrete-histogram data #:label "Hello"))))
(define (test3)
(let: ((h1-data : Discrete-Histogram-Data '(#(Eggs 1.5) #(Bacon 2.5) #(Pancakes 3.5)))
(h2-data : Discrete-Histogram-Data '(#(Eggs 1.4) #(Bacon 2.3) #(Pancakes 3.1))))
(plot (list (discrete-histogram
h1-data
#:skip 2.5 #:x-min 0
#:label "AMD")
(discrete-histogram
h2-data
#:skip 2.5 #:x-min 1
#:label "Intel" #:color 2 #:line-color 2))
#:x-label "Breakfast Food" #:y-label "Cooking Time (minutes)"
#:title "Cooking Times For Breakfast Food, Per Processor")))
(define (test4)
(let: ((data : Stacked-Histogram-Data
(list #(a (1 1 1)) #(b (1.5 3))
#(c ()) #(d (1/2)))))
(plot (stacked-histogram data
#:invert? #t
#:labels '("Red" #f "Blue"))
#:legend-anchor 'top-right)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.