#lang racket/gui
(require plot
"histogram-2d.rkt")
(define (histogram-2d-plot h (title "Histogram"))
(let* ((nx (histogram-2d-nx h))
(ny (histogram-2d-nx h))
(bins (histogram-2d-bins h))
(x-ranges (histogram-2d-x-ranges h))
(y-ranges (histogram-2d-y-ranges h))
(rects
(for*/list ((ix (in-range nx))
(iy (in-range ny)))
(let ((x0 (vector-ref x-ranges ix))
(x1 (vector-ref x-ranges (+ ix 1)))
(y0 (vector-ref y-ranges iy))
(y1 (vector-ref y-ranges (+ iy 1)))
(z (vector-ref bins (+ (* ix ny) iy))))
(vector (ivl x0 x1) (ivl y0 y1) (ivl 0 z))))))
(plot3d (rectangles3d rects)
#:x-min (vector-ref x-ranges 0)
#:x-max (vector-ref x-ranges (- (vector-length x-ranges) 1))
#:x-label "x"
#:y-min (vector-ref y-ranges 0)
#:y-max (vector-ref y-ranges (- (vector-length y-ranges) 1))
#:y-label "y"
#:z-min 0
#:z-max (histogram-2d-max h)
#:z-label "Count"
#:title title)))
(define (histogram-2d-plot-scaled h (title "Histogram"))
(let* ((nx (histogram-2d-nx h))
(ny (histogram-2d-nx h))
(bins (histogram-2d-bins h))
(x-ranges (histogram-2d-x-ranges h))
(y-ranges (histogram-2d-y-ranges h))
(rects
(for*/list ((ix (in-range nx))
(iy (in-range ny)))
(let ((x0 (vector-ref x-ranges ix))
(x1 (vector-ref x-ranges (+ ix 1)))
(y0 (vector-ref y-ranges iy))
(y1 (vector-ref y-ranges (+ iy 1)))
(z (vector-ref bins (+ (* ix ny) iy))))
(vector (ivl x0 x1) (ivl y0 y1) (ivl 0 z))))))
(plot3d (rectangles3d rects)
#:x-min (vector-ref x-ranges 0)
#:x-max (vector-ref x-ranges (- (vector-length x-ranges) 1))
#:x-label "x"
#:y-min (vector-ref y-ranges 0)
#:y-max (vector-ref y-ranges (- (vector-length y-ranges) 1))
#:y-label "y"
#:z-min 0
#:z-max (histogram-2d-sum h)
#:z-label "Count"
#:title title)))
(provide/contract
(histogram-2d-plot
(->* (histogram-2d?) (string?) (or/c (is-a?/c image-snip%) void?)))
(histogram-2d-plot-scaled
(->* (histogram-2d?) (string?) (or/c (is-a?/c image-snip%) void?))))