ClojureDocs(beta)

• incanter

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))

Examples:

(use '(incanter core stats charts))

;; plot the sine and cosine functions
(doto (function-plot sin (- 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)
view)

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))

Examples:

(use '(incanter core stats charts))

;; plot the sine and cosine functions
(doto (function-plot sin (- 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)
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#]))))]