1.2.3-SNAPSHOT Arrow_down_16x16

add-function

incanter.charts

  • (add-function chart function min-range max-range & options)
Adds a xy-plot of the given function to the given chart, returning
a modified version of the chart.

Options:
:series-label (default x expression)
:step-size (default (/ (- max-range min-range) 500))

See also:
function-plot, view, save, add-function, add-points, add-lines


Examples:

(use '(incanter core stats charts))

;; plot the sine and cosine functions
(doto (function-plot sin (- Math/PI) Math/PI)
(add-function cos (- Math/PI) Math/PI)
view)


;; plot two normal pdf functions
(doto (function-plot pdf-normal -3 3 :legend true)
(add-function (fn [x] (pdf-normal x :mean 0.5 :sd 0.5)) -3 3)
view)


;; plot a user defined function and its derivative
(use '(incanter core charts optimize))

;; define the function, x^3 + 2x^2 + 2x + 3
(defn cubic [x] (+ (* x x x) (* 2 x x) (* 2 x) 3))

;; use the derivative function to get a function
;; that approximates its derivative
(def deriv-cubic (derivative cubic))

;; plot the cubic function and its derivative
(doto (function-plot cubic -10 10)
(add-function deriv-cubic -10 10)
view)

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:596 top

(defmacro add-function
" Adds a xy-plot of the given function to the given chart, returning
  a modified version of the chart.

  Options:
    :series-label (default x expression)
    :step-size (default (/ (- max-range min-range) 500))

  See also:
    function-plot, view, save, add-function, add-points, add-lines


  Examples:

    (use '(incanter core stats charts))

    ;; plot the sine and cosine functions
    (doto (function-plot sin (- Math/PI) Math/PI)
          (add-function cos (- Math/PI) Math/PI)
          view)


    ;; plot two normal pdf functions
    (doto (function-plot pdf-normal -3 3 :legend true)
          (add-function (fn [x] (pdf-normal x :mean 0.5 :sd 0.5)) -3 3)
          view)


    ;; plot a user defined function and its derivative
    (use '(incanter core charts optimize))

    ;; define the function, x^3 + 2x^2 + 2x + 3
    (defn cubic [x] (+ (* x x x) (* 2 x x) (* 2 x) 3))

    ;; use the derivative function to get a function
    ;; that approximates its derivative
    (def deriv-cubic (derivative cubic))

    ;; plot the cubic function and its derivative
    (doto (function-plot cubic -10 10)
          (add-function deriv-cubic -10 10)
          view)

"
  ([chart function min-range max-range & options]
    `(let [opts# ~(when options (apply assoc {} options))
           series-lab# (or (:series-label opts#) (str '~function))
           args# (concat [~chart ~function ~min-range ~max-range] 
			 (apply concat (seq (apply assoc opts# 
						   [:series-label series-lab#]))))]
        (apply add-function* args#))))
Vars in incanter.charts/add-function: apply assoc defmacro when concat let list or seq str vector
Used in 0 other vars

Comments top

No comments for add-function. Log in to add a comment.