Files
graphly/geom.ipynb
T

35 KiB

In [1]:
(require '[thi.ng.geom.viz.core :as viz]
         '[thi.ng.geom.svg.core :as svg]
         '[thi.ng.geom.core.vector :as v]
         '[thi.ng.color.core :as col]
         '[thi.ng.math.core :as m :refer [PI TWO_PI]]
         '[clojupyter.misc.display :as display])
In [24]:

(defn export-viz
  [spec]
  (->> spec
       (viz/svg-plot2d-cartesian)
       (svg/svg {:width 985 :height 600})
       (svg/serialize)))

(def spec
  {:x-axis (viz/log-axis
            {:domain [1 201]
             :range  [50 (- 985 10)]
             :pos    550})
   :y-axis (viz/linear-axis
            {:domain      [0.1 100]
             :range       [550 20]
             :major       10
             :minor       5
             :pos         50
             :label-dist  15
             :label-style {:text-anchor "end"}})
   :grid   {:attribs {:stroke "#caa"}
            :minor-x true
            :minor-y true}
   :data   [{:values  (map (juxt identity #(Math/sqrt %)) (range 0 200 2))
             :attribs {:fill "#0af" :stroke "none"}
             :layout  viz/svg-scatter-plot}
            {:values  (map (juxt identity #(m/random %)) (range 0 200 2))
             :attribs {:fill "none" :stroke "#f60"}
             :shape   (viz/svg-triangle-down 6)
             :layout  viz/svg-scatter-plot}]})
Out [24]:
#'user/spec
In [25]:
(-> spec
    (export-viz)
    (display/make-html))
Out [25]:
1.0010.00100.0010.0020.0030.0040.0050.0060.0070.0080.0090.00100.00
In [26]:
(-> spec
    (assoc :y-axis (viz/log-axis
                    {:domain      [0.1 101]
                     :range       [550 20]
                     :pos         50
                     :label-dist  15
                     :label-style {:text-anchor "end"}}))
   (export-viz)
   (display/make-html))
Out [26]:
1.0010.00100.000.101.0010.00100.00
In [ ]: