Skip to content

Commit

Permalink
[viz] add line plot & example
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 6, 2015
1 parent 505c908 commit 1432494
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions geom-viz/src/core.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [[#namespace-thinggeomvizcore][Namespace: thi.ng.geom.viz.core]]
- [[#example-usage][Example usage]]
- [[#scatter-plot][Scatter plot]]
- [[#line-plot][Line plot]]
- [[#contour-plot][Contour plot]]
- [[#scales][Scales]]
- [[#linear-scale][Linear scale]]
Expand All @@ -14,6 +15,7 @@
- [[#logarithmic][Logarithmic]]
- [[#2d-plotting-svg][2D Plotting (SVG)]]
- [[#generic-plotting-helpers][Generic plotting helpers]]
- [[#line-plot][Line plot]]
- [[#scatter-plot][Scatter plot]]
- [[#contour-lines][Contour lines]]
- [[#custom-shape-drawing][Custom shape drawing]]
Expand Down Expand Up @@ -52,6 +54,31 @@
(spit "scatter.svg"))
#+END_SRC

*** Line plot

[[http://media.thi.ng/geom/viz/lineplot.svg]]

#+BEGIN_SRC clojure :noweb-ref example1
(require '[thi.ng.geom.viz.core :as viz] :reload)
(require '[thi.ng.geom.svg.core :as svg])
(require '[thi.ng.math.core :as m])

(->> {:x-axis (viz/linear-axis [(- m/PI) m/PI] [50 590] 550 10 0)
:y-axis (viz/linear-axis [-1.2 1.2] [550 20] 50 5 1)
:grid {:attribs {:stroke "#caa"}
:minor-x true
:minor-y true}
:data [{:values (map
(fn [t] (let [x (m/mix (- m/PI) m/PI t)] [x (Math/sin x)]))
(m/norm-range 100))
:attribs {:fill "none" :stroke "#0af"}
:layout viz/svg-line-plot}]}
(viz/svg-plot2d)
(svg/svg {:width 600 :height 600})
(svg/serialize)
(spit "lineplot.svg"))
#+END_SRC

*** Contour plot

| [[http://media.thi.ng/geom/viz/contours.svg]] | [[http://media.thi.ng/geom/viz/contours-outline.svg]] |
Expand Down Expand Up @@ -239,6 +266,25 @@
(if y-axis (svg-y-axis y-axis))))
#+END_SRC

*** Line plot

#+BEGIN_SRC clojure :noweb-ref plot-2d
(defn svg-line-plot
[{:keys [x-axis y-axis]} {:keys [values attribs]}]
(let [scale-x (:scale x-axis)
scale-y (:scale y-axis)
[r1 r2] (:range y-axis)
range' (if (< r1 r2) [r1 r2] [r2 r1])]
(svg/line-strip
(sequence
(comp
(filter #(m/in-range? (:domain x-axis) (first %)))
(map (fn [[x y]] [(scale-x x) (scale-y y)]))
(filter #(m/in-range? range' (second %))))
values)
attribs)))
#+END_SRC

*** Scatter plot

#+BEGIN_SRC clojure :noweb-ref plot-2d
Expand Down

0 comments on commit 1432494

Please sign in to comment.