Skip to content

Commit

Permalink
python plotting - added examples draft
Browse files Browse the repository at this point in the history
  • Loading branch information
daslu committed Jul 23, 2024
1 parent cba059a commit 1e38fd7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/scicloj/noj/v1/vis/python.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,43 @@
(-> path
slurp
kind/html)))


;; ## Using Python visualizations

;; Noj offers methods to include Python plots in [Kindly](https://scicloj.github.io/kindly-noted/kindly) visualizations: the `vis.python/with-pyplot` macro and the `vis.python/pyplot` function.

;; They are based on the [Parens for Pyplot](http://gigasquidsoftware.com/blog/2020/01/18/parens-for-pyplot/) blog post at Squid's blog.

(require-python '[numpy :as np]
'[numpy.random :as np.random]
'matplotlib.pyplot
'[seaborn :as sns]
'json)

(def sine-data
(-> {:x (range 0 (* 3 np/pi) 0.1)}
tc/dataset
(tc/add-column :y #(tcc/sin (:x %)))))

(vis.python/with-pyplot
(matplotlib.pyplot/plot
(:x sine-data)
(:y sine-data)))

(vis.python/pyplot
#(matplotlib.pyplot/plot
(:x sine-data)
(:y sine-data)))

;; https://seaborn.pydata.org/tutorial/introduction
(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")))

0 comments on commit 1e38fd7

Please sign in to comment.