1.2.3-SNAPSHOT permalink Arrow_down_16x16

xy-plot

incanter.charts

  • (xy-plot)
  • (xy-plot x y & options)
Returns a JFreeChart object representing a xy-plot of the given data.
Use the 'view' function to display the chart, or the 'save' function
to write it to a file.

Options:
:data (default nil) If the :data option is provided a dataset,
column names can be used instead of sequences
of data as arguments to xy-plot.
:title (default 'XY Plot') main title
:x-label (default x expression)
:y-label (default 'Frequency')
:legend (default false) prints legend
:series-label (default x expression)
:group-by (default nil) -- a vector of values used to group the x and y values into series.

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

Examples:

(use '(incanter core stats charts))

;; plot the cosine function
(def x (range -1 5 0.01))
(def y (cos (mult 2 Math/PI x)))
(view (xy-plot x y))

;; plot gamma pdf with different parameters
(def x2 (range 0 20 0.1))
(def gamma-plot (xy-plot x2 (pdf-gamma x2 :shape 1 :rate 2)
:legend true
:title "Gamma PDF"
:y-label "Density"))
(view gamma-plot)
(add-lines gamma-plot x2 (pdf-gamma x2 :shape 2 :rate 2))
(add-lines gamma-plot x2 (pdf-gamma x2 :shape 3 :rate 2))
(add-lines gamma-plot x2 (pdf-gamma x2 :shape 5 :rate 1))
(add-lines gamma-plot x2 (pdf-gamma x2 :shape 9 :rate 0.5))

;; use :group-by option
(use '(incanter core charts datasets))

(with-data (get-dataset :chick-weight)
(view (xy-plot :Time :weight :group-by :Chick)))


;; see INCANTER_HOME/examples/probability_plots.clj for more examples of plots

References:
http://www.jfree.org/jfreechart/api/javadoc/
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/JFreeChart.html

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

(defmacro xy-plot
" Returns a JFreeChart object representing a xy-plot of the given data.
  Use the 'view' function to display the chart, or the 'save' function
  to write it to a file.

  Options:
    :data (default nil) If the :data option is provided a dataset, 
                        column names can be used instead of sequences 
                        of data as arguments to xy-plot.
    :title (default 'XY Plot') main title
    :x-label (default x expression)
    :y-label (default 'Frequency')
    :legend (default false) prints legend
    :series-label (default x expression)
    :group-by (default nil) -- a vector of values used to group the x and y values into series.

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

  Examples:

    (use '(incanter core stats charts))

    ;; plot the cosine function
    (def x (range -1 5 0.01))
    (def y (cos (mult 2 Math/PI x)))
    (view (xy-plot x y))

    ;; plot gamma pdf with different parameters
    (def x2 (range 0 20 0.1))
    (def gamma-plot (xy-plot x2 (pdf-gamma x2 :shape 1 :rate 2)
                               :legend true
                               :title \"Gamma PDF\"
                               :y-label \"Density\"))
    (view gamma-plot)
    (add-lines gamma-plot x2 (pdf-gamma x2 :shape 2 :rate 2))
    (add-lines gamma-plot x2 (pdf-gamma x2 :shape 3 :rate 2))
    (add-lines gamma-plot x2 (pdf-gamma x2 :shape 5 :rate 1))
    (add-lines gamma-plot x2 (pdf-gamma x2 :shape 9 :rate 0.5))

    ;; use :group-by option
    (use '(incanter core charts datasets))

    (with-data (get-dataset :chick-weight)
      (view (xy-plot :Time :weight :group-by :Chick)))


    ;; see INCANTER_HOME/examples/probability_plots.clj for more examples of plots

  References:
    http://www.jfree.org/jfreechart/api/javadoc/
    http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/JFreeChart.html

"
  ([]
     `(xy-plot [] [] :x-label "x" :y-label "y"))
  ([x y & options]
    `(let [opts# ~(when options (apply assoc {} options))
           group-by# (:group-by opts#) 
           main-title# (or (:title opts#) "")
           x-lab# (or (:x-label opts#) (str '~x))
           y-lab# (or (:y-label opts#) (str '~y))
           series-lab# (or (:series-label opts#) 
			   (if group-by#
			     (format "%s, %s (0)" '~x '~y) 
			     (format "%s, %s" '~x '~y)))
	   args# (concat [~x ~y ~create-xy-plot] (apply concat (seq (apply assoc opts# 
							   [:group-by group-by# 
							    :main-title main-title# 
							    :x-label x-lab# 
							    :y-label y-lab# 
							    :series-label series-lab#]))))]
        (apply xy-plot* args#))))
Vars in incanter.charts/xy-plot: apply assoc defmacro when concat format let list or seq str vector
Used in 0 other vars

Comments top

No comments for xy-plot. Log in to add a comment.