File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
projects/datavis/python/plotting/notebooks Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1
1
(ns index
2
2
(:require [libpython-clj2.require :refer [require-python]]
3
3
[libpython-clj2.python :refer [py. py.. py.-] :as py]))
4
+
5
+
6
+ ; ; inspiration: http://gigasquidsoftware.com/blog/2020/01/18/parens-for-pyplot/
7
+
8
+ (require-python 'matplotlib.pyplot
9
+ 'matplotlib.backends.backend_agg
10
+ 'numpy)
11
+
12
+ (defmacro with-pyplot
13
+ " Takes forms with mathplotlib.pyplot and returns a showable (SVG) plot."
14
+ [& body]
15
+ `(let [_# (matplotlib.pyplot/clf )
16
+ fig# (matplotlib.pyplot/figure )
17
+ agg-canvas# (matplotlib.backends.backend_agg/FigureCanvasAgg fig#)
18
+ path# (:path (tempfiles/tempfile! " .svg" ))]
19
+ ~(cons 'do body)
20
+ (py. agg-canvas# " draw" )
21
+ (matplotlib.pyplot/savefig path#)
22
+ (-> path#
23
+ slurp
24
+ kind/html)))
25
+
26
+
27
+ (defn pyplot
28
+ " Takes a function plotting using mathplotlib.pyplot, and returns a showable (SVG) plot"
29
+ [plotting-function]
30
+ (let [_ (matplotlib.pyplot/clf )
31
+ fig (matplotlib.pyplot/figure )
32
+ agg-canvas (matplotlib.backends.backend_agg/FigureCanvasAgg fig)
33
+ path (:path (tempfiles/tempfile! " .svg" ))]
34
+ (plotting-function )
35
+ (py. agg-canvas " draw" )
36
+ (matplotlib.pyplot/savefig path)
37
+ (-> path
38
+ slurp
39
+ kind/html)))
You can’t perform that action at this time.
0 commit comments