proposed efficiency -- requires that only xref'able storage be used.
[CommonLispStat.git] / examples / plotting-data.lisp
blobe9d19504c46a7f5ad6fc9f8d904c5cf3fad779c2
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-07-06 18:45:27 tony>
4 ;;; Creation: <2009-03-12 17:14:56 tony>
5 ;;; File: plotting-data.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2009--, AJ Rossini. BSD, LLGPL, or GPLv2, depending
8 ;;; on how it arrives.
9 ;;; Purpose: Example of generating plots.
11 ;;; What is this talk of 'release'? Klingons do not make software
12 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
13 ;;; designers and quality assurance people in its wake.
15 ;;; This organization and structure is new to the 21st Century
16 ;;; version.. Think, "21st Century Schizoid Man".
18 ;; SETUP FOR PLOT EXAMPLE:
20 (defpackage :cl-2d-user-x11
21 (:use :cl :cl-cairo2 :cl-2d :cl-numlib :cl-colors :bind :cls))
23 (in-package :cl-2d-user-x11)
25 ;; PLOT EXAMPLE
26 #+nil
27 (progn
30 ;; this is how you create an X11 frame. If you supply a
31 ;; background-color to as-frame, each plot will clear the frame with
32 ;; this color.
34 (defparameter *frame1* (as-frame (create-xlib-image-context 300 300)
35 :background-color +white+))
37 ;; or netbook size, picture is similar but on a lower-res display window.
38 (defparameter *frame2* (as-frame (create-xlib-image-context 200 200)
39 :background-color +white+))
41 (plot-function *frame1*
42 #'exp (interval-of 0 2)
43 :x-title "x"
44 :y-title "exp(x)")
46 ;; split the frame, and you can draw on the subframes independently.
47 ;; I do this a lot.
49 (bind ((#2A((f1 f2) (f3 f4))
50 (split-frame *frame2* (percent 50) (percent 50))))
51 (defparameter *f1* f1)
52 (defparameter *f2* f2)
53 (defparameter *f3* f3)
54 (defparameter *f4* f4))
57 (bind ((#2A((f1 f2) (f3 f4))
58 (split-frame *frame2* (percent 75) (percent 25))))
59 (defparameter *f1* f1)
60 (defparameter *f2* f2)
61 (defparameter *f3* f3)
62 (defparameter *f4* f4))
64 (plot-function *f1* #'sin (interval-of 0 2) :x-title "x" :y-title "sin(x)")
65 (plot-function *f2* #'cos (interval-of 0 2) :x-title "x" :y-title "cos(x)")
66 (plot-function *f3* #'tan (interval-of 0 2) :x-title "x" :y-title "tan(x)")
67 (plot-function *f4* #'/ (interval-of 0 2) :x-title "x" :y-title "1/x")
69 (clear *frame1*)
72 (let* ((n 500)
73 (xs (num-sequence :from 0 :to 10 :length n))
74 (ys (map 'vector #'(lambda (x) (+ x 8 (random 4.0))) xs))
75 (weights (replicate #'(lambda () (1+ (random 10))) n 'fixnum))
76 (da (plot-simple *frame1* (interval-of 0 10) (interval-of 10 20)
77 :x-title "x" :y-title "y")))
78 (draw-symbols da xs ys :weights weights))
80 (xlib-image-context-to-png (context *frame1*) "/home/tony/test1.png")
81 (xlib-image-context-to-png (context *frame2*) "/home/tony/test2.png")
85 ;;; EXAMPLE FOR DSC2009
86 (defparameter *frame2* (as-frame (create-xlib-image-context 400 400)
87 :background-color +white+))
89 (bind ((#2A((f1 f2) (f3 f4))
90 (split-frame *frame2* (percent 50) (percent 50))))
91 (defparameter *f1* f1)
92 (defparameter *f2* f2)
93 (defparameter *f3* f3)
94 (defparameter *f4* f4))
95 (plot-function *f1* #'sin (interval-of 0 2) :x-title "x" :y-title "sin(x)")
96 (plot-function *f2* #'cos (interval-of 0 2) :x-title "x" :y-title "cos(x)")
97 (plot-function *f3* #'tan (interval-of 0 2) :x-title "x" :y-title "tan(x)")
99 (num-sequence :from 0 :to 10 :length 30)
101 (let* ((n 500)
102 (xs (num-sequence :from 0 :to 10 :length n))
103 (ys (map 'vector #'(lambda (x) (+ x 8 (random 4.0))) xs))
104 (weights (replicate #'(lambda () (1+ (random 10))) n 'fixnum))
105 (da (plot-simple *f4* (interval-of 0 10) (interval-of 10 20)
106 :x-title "x" :y-title "y")))
107 (draw-symbols da xs ys :weights weights))
108 (xlib-image-context-to-png (context *f1*) "/home/tony/test1.png")
109 (xlib-image-context-to-png (context *frame2*) "/home/tony/test2.png")
110 (destroy (context *frame2*))