diff --git a/geom-viz/src/core.org b/geom-viz/src/core.org index b37e7aab..479bfd9d 100644 --- a/geom-viz/src/core.org +++ b/geom-viz/src/core.org @@ -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]] @@ -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]] @@ -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]] | @@ -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