From 383e68a7b8c4304478cfe99d2e06e54d21368db7 Mon Sep 17 00:00:00 2001 From: daslu Date: Mon, 26 Jun 2023 00:33:02 +0300 Subject: [PATCH] updated docs --- docs/intro/image.html | 9880 +++++++++++++++++++++++++++ docs/intro/python.html | 9925 +++++++++++++++++++++++++++ docs/intro/visualization.html | 10009 ++++++++++++++++++++++++++++ notebooks/intro/image.clj | 6 +- notebooks/intro/python.clj | 5 - notebooks/intro/visualization.clj | 94 +- 6 files changed, 29905 insertions(+), 14 deletions(-) create mode 100644 docs/intro/image.html create mode 100644 docs/intro/python.html create mode 100644 docs/intro/visualization.html diff --git a/docs/intro/image.html b/docs/intro/image.html new file mode 100644 index 0000000..6ffd2f3 --- /dev/null +++ b/docs/intro/image.html @@ -0,0 +1,9880 @@ + + + + + +
/workspace/Dropbox/projects/scicloj/noj/notebooks/intro/image.clj
(ns intro.image
+  (:require [tech.v3.tensor :as tensor]
+            [tech.v3.datatype.functional :as fun]
+            [scicloj.noj.v1.vis.image :as vis.image]))
...

Turning tensors into images

(-> (for [i (range 100)]
+      (range 100))
+    tensor/ensure-tensor
+    (fun/* 400)
+    (vis.image/tensor->image :ushort-gray))
...
\ No newline at end of file diff --git a/docs/intro/python.html b/docs/intro/python.html new file mode 100644 index 0000000..34f3c41 --- /dev/null +++ b/docs/intro/python.html @@ -0,0 +1,9925 @@ + + + + + +
/workspace/Dropbox/projects/scicloj/noj/notebooks/intro/python.clj
(ns intro.python
+  (:require [scicloj.kind-clerk.api :as kind-clerk]
+            [tablecloth.api :as tc]
+            [scicloj.noj.v1.vis.python :as vis.python]
+            [libpython-clj2.require :refer [require-python]]
+            [libpython-clj2.python :refer [py. py.. py.-] :as py]
+            [tech.v3.datatype :as dtype]
+            [tech.v3.datatype.functional :as fun]
+            [scicloj.kindly.v3.api :as kindly]
+            [scicloj.kindly.v3.kind :as kind]
+            [hiccup.core :as hiccup]
+            hiccup.util))
...

Using Python visualizations

(require-python '[numpy :as np]
+                '[numpy.random :as np.random]
+                'matplotlib.pyplot
+                '[seaborn :as sns]
+                'json
+                '[arviz :as az])
:ok
+
(def sine-data
+  (-> {:x (range 0 (* 3 np/pi) 0.1)}
+      tc/dataset
+      (tc/add-column :y #(fun/sin (:x %)))))
...
(vis.python/with-pyplot
+  ;; http://gigasquidsoftware.com/blog/2020/01/18/parens-for-pyplot/
+  (matplotlib.pyplot/plot
+   (:x sine-data)
+   (:y sine-data)))
...
(vis.python/pyplot
+ #(matplotlib.pyplot/plot
+   (:x sine-data)
+   (:y sine-data)))
...
(let [tips (sns/load_dataset "tips")]
+  (sns/set_theme)
+  (vis.python/pyplot
+   #(sns/relplot :data tips
+                 :x "total_bill"
+                 :y "tip"
+                 :col "time"
+                 :hue "smoker"
+                 :style "smoker"
+                 :size "size")))
...
(let [size [10 50]
+      data {:normal (apply np.random/randn size)
+            :gumbel (np.random/gumbel :size size)
+            :student_t (np.random/standard_t :df 6
+                                             :size size)
+            :exponential (np.random/exponential :size size)}]
+  (vis.python/pyplot
+   #(az/plot_forest data)))
...
:bye
:bye
+
\ No newline at end of file diff --git a/docs/intro/visualization.html b/docs/intro/visualization.html new file mode 100644 index 0000000..07b9d3d --- /dev/null +++ b/docs/intro/visualization.html @@ -0,0 +1,10009 @@ + + + + + +
/workspace/Dropbox/projects/scicloj/noj/notebooks/intro/visualization.clj
(ns intro.visualization
+  (:require [scicloj.kind-clerk.api :as kind-clerk]
+            [tablecloth.api :as tc]
+            [aerial.hanami.templates :as ht]
+            [scicloj.noj.v1.vis :as vis]
+            [scicloj.noj.v1.stats :as stats]
+            [tech.v3.datatype :as dtype]
+            [tech.v3.datatype.functional :as fun]
+            [scicloj.kindly.v3.api :as kindly]
+            [scicloj.kindly.v3.kind :as kind]
+            [hiccup.core :as hiccup]
+            [clojure2d.color :as color]))
...

Raw html

(-> "

Hello, Noj.

" + vis/raw-html)
...
(-> [:svg {:height 210
+           :width 500}
+     [:line {:x1 0
+             :y1 0
+             :x2 200
+             :y2 200
+             :style "stroke:rgb(255,0,0);stroke-width:2"}]]
+    hiccup/html
+    vis/raw-html)
...

Visualizing datases with Hanami

(def dataset1
+  (-> {:x (range 9)
+       :y (map +
+               (range 9)
+               (repeatedly 9 rand))}
+      tc/dataset))
...

A simple plot

plotting a Tablecloth datasete based on a Hanami template

(-> dataset1
+    (vis/hanami-plot ht/point-chart
+                     {:MSIZE 200}))
...

Layers

(-> dataset1
+    (vis/hanami-layers
+     {:TITLE "points and a line"}
+     [(vis/hanami-plot nil
+                       ht/point-chart
+                       {:MSIZE 400})
+      (vis/hanami-plot nil
+                       ht/line-chart
+                       {:MSIZE 4
+                        :MCOLOR "brown"})]))
...

Concatenation

(-> dataset1
+    (vis/hanami-vconcat
+     {}
+     [(vis/hanami-plot nil
+                       ht/point-chart
+                       {:MSIZE 400
+                        :HEIGHT 100
+                        :WIDTH 100})
+      (vis/hanami-plot nil
+                       ht/line-chart
+                       {:MSIZE 4
+                        :MCOLOR "brown"
+                        :HEIGHT 100
+                        :WIDTH 100})]))
...
(-> dataset1
+    (vis/hanami-hconcat
+     {}
+     [(vis/hanami-plot nil
+                       ht/point-chart
+                       {:MSIZE 400
+                        :HEIGHT 100
+                        :WIDTH 100})
+      (vis/hanami-plot nil
+                       ht/line-chart
+                       {:MSIZE 4
+                        :MCOLOR "brown"
+                        :HEIGHT 100
+                        :WIDTH 100})]))
...

Combining a few things together

The following is inspired by the example at Plotnine's main page.

(def mtcars
+  (-> "/tmp/mtcars.csv"
+      (tc/dataset {:key-fn keyword})))
...
(let [pallete (->> :accent
+                   color/palette
+                   (mapv color/format-hex))]
+  (-> mtcars
+      (tc/group-by :gear {:result-type :as-map})
+      (->> (sort-by key)
+           (map-indexed
+            (fn [i [group-name ds]]
+              (-> ds
+                  (stats/add-predictions :mpg [:wt]
+                                         {:model-type :smile.regression/ordinary-least-square})
+                  (vis/hanami-layers {:TITLE (str "grear=" group-name)}
+                                     [(vis/hanami-plot nil
+                                                       ht/point-chart
+                                                       {:X :wt
+                                                        :Y :mpg
+                                                        :MSIZE 200
+                                                        :MCOLOR (pallete i)
+                                                        :HEIGHT 200
+                                                        :WIDTH 200})
+                                      (vis/hanami-plot nil
+                                                       ht/line-chart
+                                                       {:X :wt
+                                                        :Y :mpg-prediction
+                                                        :MSIZE 5
+                                                        :MCOLOR (pallete i)
+                                                        :YTITLE :mpg})]
+                                     ))))
+           (vis/hanami-hconcat nil {}))))
...
:bye
:bye
+
\ No newline at end of file diff --git a/notebooks/intro/image.clj b/notebooks/intro/image.clj index 113f50c..722ebed 100644 --- a/notebooks/intro/image.clj +++ b/notebooks/intro/image.clj @@ -1,11 +1,9 @@ (ns intro.image - (:require [scicloj.kind-clerk.api :as kind-clerk] - [tech.v3.tensor :as tensor] + (:require [tech.v3.tensor :as tensor] [tech.v3.datatype.functional :as fun] [scicloj.noj.v1.vis.image :as vis.image])) -;; ## Adapt Clerk to Kindly -(kind-clerk/setup!) +;; ## Turning tensors into images (-> (for [i (range 100)] (range 100)) diff --git a/notebooks/intro/python.clj b/notebooks/intro/python.clj index f804684..efa89e9 100644 --- a/notebooks/intro/python.clj +++ b/notebooks/intro/python.clj @@ -12,11 +12,6 @@ hiccup.util)) -;; ## Setup - -;; Adapt Clerk to Kindly -(kind-clerk/setup!) - ;; ## Using Python visualizations (require-python '[numpy :as np] diff --git a/notebooks/intro/visualization.clj b/notebooks/intro/visualization.clj index cbe3650..a206c39 100644 --- a/notebooks/intro/visualization.clj +++ b/notebooks/intro/visualization.clj @@ -3,17 +3,15 @@ [tablecloth.api :as tc] [aerial.hanami.templates :as ht] [scicloj.noj.v1.vis :as vis] + [scicloj.noj.v1.stats :as stats] [tech.v3.datatype :as dtype] [tech.v3.datatype.functional :as fun] [scicloj.kindly.v3.api :as kindly] [scicloj.kindly.v3.kind :as kind] [hiccup.core :as hiccup] - hiccup.util)) + [clojure2d.color :as color])) -;; ## Adapt Clerk to Kindly -(kind-clerk/setup!) - ;; ## Raw html (-> "

Hello, Noj.

" vis/raw-html) @@ -36,9 +34,95 @@ (repeatedly 9 rand))} tc/dataset)) +;; ### A simple plot + +;; plotting a Tablecloth datasete based on a Hanami template + (-> dataset1 (vis/hanami-plot ht/point-chart - :MSIZE 200)) + {:MSIZE 200})) + +;; ### Layers + +(-> dataset1 + (vis/hanami-layers + {:TITLE "points and a line"} + [(vis/hanami-plot nil + ht/point-chart + {:MSIZE 400}) + (vis/hanami-plot nil + ht/line-chart + {:MSIZE 4 + :MCOLOR "brown"})])) + +;; ### Concatenation + +(-> dataset1 + (vis/hanami-vconcat + {} + [(vis/hanami-plot nil + ht/point-chart + {:MSIZE 400 + :HEIGHT 100 + :WIDTH 100}) + (vis/hanami-plot nil + ht/line-chart + {:MSIZE 4 + :MCOLOR "brown" + :HEIGHT 100 + :WIDTH 100})])) + +(-> dataset1 + (vis/hanami-hconcat + {} + [(vis/hanami-plot nil + ht/point-chart + {:MSIZE 400 + :HEIGHT 100 + :WIDTH 100}) + (vis/hanami-plot nil + ht/line-chart + {:MSIZE 4 + :MCOLOR "brown" + :HEIGHT 100 + :WIDTH 100})])) + +;; ### Combining a few things together +;; +;; The following is inspired by the example at Plotnine's [main page](https://plotnine.readthedocs.io/en/stable/). + +(def mtcars + (-> "/tmp/mtcars.csv" + (tc/dataset {:key-fn keyword}))) +(let [pallete (->> :accent + color/palette + (mapv color/format-hex))] + (-> mtcars + (tc/group-by :gear {:result-type :as-map}) + (->> (sort-by key) + (map-indexed + (fn [i [group-name ds]] + (-> ds + (stats/add-predictions :mpg [:wt] + {:model-type :smile.regression/ordinary-least-square}) + (vis/hanami-layers {:TITLE (str "grear=" group-name)} + [(vis/hanami-plot nil + ht/point-chart + {:X :wt + :Y :mpg + :MSIZE 200 + :MCOLOR (pallete i) + :HEIGHT 200 + :WIDTH 200}) + (vis/hanami-plot nil + ht/line-chart + {:X :wt + :Y :mpg-prediction + :MSIZE 5 + :MCOLOR (pallete i) + :YTITLE :mpg})] + )))) + (vis/hanami-hconcat nil {})))) :bye