histogram-2d-graphics.ss
#lang scheme/base
;;; PLT Scheme Science Collection
;;; histogram-2d-graphics.ss
;;; Copyright (c) 2004-2008 M. Douglas Williams
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
;;; License as published by the Free Software Foundation; either
;;; version 2.1 of the License, or (at your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with this library; if not, write to the Free
;;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
;;; 02111-1307 USA.
;;;
;;; -------------------------------------------------------------------
;;;
;;; This module implements the graphics for 2D histograms.
;;;
;;; Version  Date      Description
;;; 1.0.0    09/29/04  Marked as ready for Release 1.0.  (Doug
;;;                    Williams)
;;; 3.0.0    06/09/08  Changes required for V4.0.  (Doug Williams)
;;; 3.0.1    07/01/08  Changed axes labels.  (Doug Williams)

(require "histogram-2d.ss"
         (lib "plot.ss" "plot")
         "plot-histogram-2d.ss"
         (lib "contract.ss"))

(provide/contract
 (histogram-2d-plot
  (case-> (-> histogram-2d? string? any)
          (-> histogram-2d? any))))

(define histogram-2d-plot
  (case-lambda
    ((h title)
     (let ((bins (histogram-2d-bins h))
           (x-ranges (histogram-2d-x-ranges h))
           (y-ranges (histogram-2d-y-ranges h)))
       (plot3d (histogram-2d (list bins x-ranges y-ranges))
               (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))))
    ((h)
     (histogram-2d-plot h "2D Histogram"))))