Skip to content

Commit

Permalink
noj-book.visualizing-correlation-matrices - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
daslu committed Apr 17, 2024
1 parent b573d3c commit 09c2f72
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion notebooks/noj_book/visualizing_correlation_matrices.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

(ns noj-book.visualizing-correlation-matrices
(:require [fastmath.stats]
[fastmath.core :as fastmath]
[tablecloth.api :as tc]
[noj-book.datasets]))
[noj-book.datasets]
[scicloj.kindly.v4.kind :as kind]
[clojure.math :as math]))

;; ## Auxiliary functions

Expand Down Expand Up @@ -59,3 +62,51 @@
;; For example:
(-> noj-book.datasets/iris
(correlations-dataset [:sepal-length :sepal-width :petal-length :petal-width]))

;; ## Drawing a heatmap using Echarts

;; The following function is inspired by
;; [an Apache Echarts heatmap tutorial](https://github.com/apache/echarts/blob/master/test/heatmap-large.html).

(defn echarts-heatmap [{:keys [xyz-data xs ys
min max
series-name]
:or {series-name ""}}]
(kind/echarts
{:tooltip {}
:xAxis {:type :category
:data xs}
:yAxis {:type :category
:data ys}
:visualMap {:min min
:max max
:calculable true
:splitNumber 8
:inRange {:color
["#313695" "#4575b4" "#74add1"
"#abd9e9" "#e0f3f8" "#ffffbf"
"#fee090" "#fdae61" "#f46d43"
"#d73027" "#a50026"]}}
:series [{:name series-name
:type :heatmap
:data xyz-data
:itemStyle {:emphasis {:borderColor "#333"
:borderWidth 2}}
:progressive 1000
:animation false}]}))

;; Here is an example using synthetic data:

(let [n 30]
(echarts-heatmap
{:xyz-data (for [i (range n)
j (range n)]
[i j (fastmath/logistic (* (+ (- i j))
(rand)
(/ 2 (double n))))])
:x-data (range n)
:y-data (range n)
:min 0
:max 1}))

;; Note that this plot supports tooltips.

0 comments on commit 09c2f72

Please sign in to comment.