1.2.3-SNAPSHOT permalink Arrow_down_16x16

sliders

incanter.charts

  • (sliders [& slider-bindings] body)
Creates one slider control for each of the given sequence bindings.
Each slider calls the given expression when manipulated.


Examples:
(use '(incanter core stats charts))

;; manipulate a normal pdf
(let [x (range -3 3 0.1)]
(def pdf-chart (xy-plot))
(view pdf-chart)
(sliders [mean (range -3 3 0.1)
stdev (range 0.1 10 0.1)]
(set-data pdf-chart [x (pdf-normal x :mean mean :sd stdev)])))



;; manipulate a gamma pdf
(let [x (range 0 20 0.1)]
(def pdf-chart (xy-plot))
(view pdf-chart)
(sliders [rate (range 0.1 10 0.1)
shape (range 0.1 10 0.1)]
(set-data pdf-chart [x (pdf-gamma x :rate rate :shape shape)])))



;; find the start values of a non-linear model function
(use '(incanter core charts datasets))
;; create model function used in the following data-sorcery post:
;; http://data-sorcery.org/2009/06/06/fitting-non-linear-models/

(defn f [theta x]
(let [[b1 b2 b3] theta]
(div (exp (mult (minus b1) x)) (plus b2 (mult b3 x)))))


(with-data (get-dataset :chwirut)
(view $data)
(def chart (scatter-plot ($ :x) ($ :y)))
(view chart)
(add-lines chart ($ :x) (f [0 0.01 0] ($ :x)))

;; manipulate the model line to find some good start values.
;; give the index of the line data (i.e. 1) to set-data.
(let [x ($ :x)]
(sliders [b1 (range 0 2 0.01)
b2 (range 0.01 2 0.01)
b3 (range 0 2 0.01)]
(set-data chart [x (f [b1 b2 b3] x)] 1))))

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source incanter/charts.clj:2861 top

(defmacro sliders
" Creates one slider control for each of the given sequence bindings. 
  Each slider calls the given expression when manipulated. 


  Examples:
  (use '(incanter core stats charts))
  
  ;; manipulate a normal pdf
  (let [x (range -3 3 0.1)]
    (def pdf-chart (xy-plot))
    (view pdf-chart) 
    (sliders [mean (range -3 3 0.1) 
  	      stdev (range 0.1 10 0.1)]
      (set-data pdf-chart [x (pdf-normal x :mean mean :sd stdev)])))



  ;; manipulate a gamma pdf
  (let [x (range 0 20 0.1)]
    (def pdf-chart (xy-plot))
    (view pdf-chart) 
    (sliders [rate (range 0.1 10 0.1) 
  	      shape (range 0.1 10 0.1)]
      (set-data pdf-chart [x (pdf-gamma x :rate rate :shape shape)])))



  ;; find the start values of a non-linear model function
  (use '(incanter core charts datasets))
  ;; create model function used in the following data-sorcery post:
  ;; http://data-sorcery.org/2009/06/06/fitting-non-linear-models/

  (defn f [theta x]
    (let [[b1 b2 b3] theta]
      (div (exp (mult (minus b1) x)) (plus b2 (mult b3 x)))))


  (with-data (get-dataset :chwirut)
    (view $data)
    (def chart (scatter-plot ($ :x) ($ :y)))
    (view chart)
    (add-lines chart ($ :x) (f [0 0.01 0] ($ :x)))

    ;; manipulate the model line to find some good start values.
    ;; give the index of the line data (i.e. 1) to set-data.
    (let [x ($ :x)] 
      (sliders [b1 (range 0 2 0.01)
	        b2 (range 0.01 2 0.01)
	        b3 (range 0 2 0.01)]
        (set-data chart [x (f [b1 b2 b3] x)] 1))))

"
  ([[& slider-bindings] body]
     `(let [slider-fn# (fn ~(apply vector (map symbol (take-nth 2 slider-bindings))) 
			 (do ~body))
	    slider-labels# ~(apply vector (map str (take-nth 2 slider-bindings)))]
	(sliders* slider-fn# ~(apply vector (take-nth 2 (rest slider-bindings))) slider-labels#))))
Vars in incanter.charts/sliders: apply defmacro map rest str symbol take-nth vector concat fn let list seq
Used in 0 other vars

Comments top

No comments for sliders. Log in to add a comment.