20  API Reference

Complete reference for every public function in scicloj.napkinsketch.api.

Each entry shows the docstring, a live example, and a test. For galleries of mark variations, see the Reference notebooks (Scatter, Distributions, Ranking, Change Over Time, Relationships).

Sample Data

(def tiny {:x [1 2 3 4 5]
           :y [2 4 1 5 3]
           :group [:a :a :b :b :b]})
(def sales {:product [:widget :gadget :gizmo :doohickey]
            :revenue [120 340 210 95]})
(def measurements {:treatment ["A" "B" "C" "D"]
                   :mean [10.0 15.0 12.0 18.0]
                   :ci_lo [8.0 12.0 9.5 15.5]
                   :ci_hi [12.0 18.0 14.5 20.5]})

Data Setup

view

[data]

[data spec-or-x]

[data x-or-spec y-or-opts]

[data x y opts]

Create views from data and column specs. Data can be a Tablecloth dataset, a map of columns ({:x [1 2 3]}), a sequence of row maps ([{:x 1 :y 2} …]), or a CSV path/URL. Column references must be keywords. (view data) — infer columns (1→x, 2→x y, 3→x y color) (view data :x :y) — two keywords, one scatter view (view data [:x :y]) — pair as vector, same result (view data [[:x1 :y1] …]) — multiple views (view data :x) — histogram view (x=y) An optional opts map sets shared aesthetics that all layers inherit: (view data :x :y {:color :species}) — layers inherit color grouping (view data :x {:color :species}) — single column + shared aesthetics Layer opts override view-level aesthetics.

Single scatter view — two columns as [x y]:

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width))
sepal widthsepal length4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

Histogram view — a single keyword means x = y (diagonal):

(-> data/iris
    (sk/lay-histogram :sepal_length))
sepal length4.55.05.56.06.57.07.58.00510152025

Multiple views — a vector of [x y] pairs:

(-> data/iris
    (sk/view [[:sepal_length :sepal_width]
              [:petal_length :petal_width]])
    (sk/lay-point {:color :species}))
speciessetosaversicolorvirginica2345sepal lengthpetal lengthsepal widthpetal width

Map form — explicit keys:

(-> (sk/view data/iris {:x :sepal_length :y :sepal_width})
    sk/lay-point)
sepal widthsepal length4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

lay

[sketch-or-views & layer-specs]

Apply one or more methods to views. Primarily used for annotations; for data layers prefer sk/lay-point, sk/lay-histogram, etc. (lay views (rule-h 5)) — horizontal reference line (lay views (rule-v 3) (band-h 1 2)) — multiple annotations

Add layers with sk/lay-point, sk/lay-lm, etc.:

(-> data/iris
    (sk/view :sepal_length :sepal_width {:color :species})
    sk/lay-point
    sk/lay-lm)
sepal widthsepal lengthspeciessetosaversicolorvirginica4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

Layer Functions

lay-point

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a scatter layer — shows individual data points. (lay-point views) — add to views (lay-point views {:color :species}) — with options (lay-point data :x :y) — from data (lay-point data :x :y {:color :species}) — from data with options

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width {:color :species}))
sepal widthsepal lengthspeciessetosaversicolorvirginica4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

lay-line

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a line layer — connects data points in order. (lay-line views) — add to views (lay-line views {:color :group}) — with options (lay-line data :x :y) — from data

(def wave {:x (range 30)
           :y (map #(Math/sin (* % 0.3)) (range 30))})
(-> wave
    (sk/lay-line :x :y))
yx051015202530-1.0-0.8-0.6-0.4-0.20.00.20.40.60.81.0

lay-histogram

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a histogram layer — bins numerical data into counted bars. (lay-histogram views) — add to views (lay-histogram views {:color :species}) — with options (lay-histogram data :x) — from data, single column

(-> data/iris
    (sk/lay-histogram :sepal_length))
sepal length4.55.05.56.06.57.07.58.00510152025

lay-bar

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a bar layer — counts categorical values. (lay-bar views) — add to views (lay-bar views {:color :species}) — with options (lay-bar data :x) — from data, single column

(-> data/iris
    (sk/lay-bar :species))
speciessetosaversicolorvirginica05101520253035404550

lay-stacked-bar

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a stacked bar layer — counts categorical values (position :stack). (lay-stacked-bar views) — add to views (lay-stacked-bar views {:color :smoker}) — with options

(-> data/penguins
    (sk/lay-stacked-bar :island {:color :species}))
islandspeciesAdelieChinstrapGentooTorgersenBiscoeDream020406080100120140160

lay-stacked-bar-fill

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a percentage stacked bar layer — proportions sum to 1.0. (lay-stacked-bar-fill views) — add to views (lay-stacked-bar-fill views {:color :smoker}) — with options

(-> data/penguins
    (sk/lay-stacked-bar-fill :island {:color :species}))
islandspeciesAdelieChinstrapGentooTorgersenBiscoeDream0.00.10.20.30.40.50.60.70.80.91.0

lay-value-bar

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a value bar layer — categorical x with pre-computed numeric y. (lay-value-bar views) — add to views (lay-value-bar data :product :revenue) — from data

(-> sales
    (sk/lay-value-bar :product :revenue))
revenueproduct:widget:gadget:gizmo:doohickey050100150200250300350

lay-lm

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a linear regression layer — fits a straight line to data. (lay-lm views) — add to views (lay-lm views {:color :species}) — per-group regression (lay-lm views {:se true}) — with confidence ribbon

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width)
    sk/lay-lm)
sepal widthsepal length4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

lay-loess

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a LOESS layer — local regression smoothing. (lay-loess views) — add to views (lay-loess views {:color :species}) — per-group smoothing (lay-loess views {:se true}) — with confidence ribbon

(def noisy-wave (let [r (rng/rng :jdk 42)]
                  {:x (range 50)
                   :y (map #(+ (Math/sin (* % 0.2)) (* 0.3 (- (rng/drandom r) 0.5)))
                           (range 50))}))
(-> noisy-wave
    (sk/lay-point :x :y)
    sk/lay-loess)
yx05101520253035404550-1.2-1.0-0.8-0.6-0.4-0.20.00.20.40.60.81.0

lay-density

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a density layer — kernel density estimation as filled area. (lay-density views) — add to views (lay-density views {:color :species}) — per-group density curves

(-> data/iris
    (sk/lay-density :sepal_length))
sepal length3456789100.00.050.10.150.20.250.30.350.4

lay-area

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add an area layer — filled region under a line. (lay-area views) — add to views (lay-area views {:color :species}) — with options

(-> wave
    (sk/lay-area :x :y))
yx0510152025300.00.20.40.60.81.01.2

lay-stacked-area

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a stacked area layer — filled regions stacked cumulatively. (lay-stacked-area views) — add to views (lay-stacked-area views {:color :group}) — with options

(-> {:x (concat (range 10) (range 10) (range 10))
     :y (concat [1 2 3 4 5 4 3 2 1 0]
                [2 2 2 3 3 3 2 2 2 2]
                [1 1 1 1 2 2 2 1 1 1])
     :group (concat (repeat 10 "A") (repeat 10 "B") (repeat 10 "C"))}
    (sk/lay-stacked-area :x :y {:color :group}))
yxgroupABC0123456789012345678910

lay-text

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a text layer — data-driven labels at (x, y) positions. (lay-text views {:text :name}) — label each point (lay-text data :x :y {:text :name}) — from data

(-> {:x [1 2 3 4] :y [4 7 5 8] :name ["A" "B" "C" "D"]}
    (sk/lay-text :x :y {:text :name}))
yxABCD1.01.52.02.53.03.54.04.04.55.05.56.06.57.07.58.0

lay-label

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a label layer — text with a filled background box. (lay-label views {:text :name}) — labeled points (lay-label data :x :y {:text :name}) — from data

(-> {:x [1 2 3 4] :y [4 7 5 8] :name ["A" "B" "C" "D"]}
    (sk/lay-point :x :y {:size 5})
    (sk/lay-label {:text :name}))
yxABCD1.01.52.02.53.03.54.04.04.55.05.56.06.57.07.58.0

lay-boxplot

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a boxplot layer — median, quartiles, whiskers, and outliers. (lay-boxplot views) — add to views (lay-boxplot views {:color :smoker}) — grouped boxplots

(-> data/iris
    (sk/lay-boxplot :species :sepal_width))
sepal widthspeciessetosaversicolorvirginica2.02.53.03.54.04.5

lay-violin

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a violin layer — mirrored density curve per category. (lay-violin views) — add to views (lay-violin views {:color :smoker}) — grouped violins

(-> data/tips
    (sk/lay-violin :day :total_bill))
total billdaySunSatThurFri-20-10010203040506070

lay-errorbar

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add an errorbar layer — vertical error bars at (x, y) positions. (lay-errorbar views {:ymin :ci_lo :ymax :ci_hi}) — with error columns

(-> measurements
    (sk/lay-point :treatment :mean)
    (sk/lay-errorbar {:ymin :ci_lo :ymax :ci_hi}))
meantreatmentABCD8101214161820

lay-lollipop

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a lollipop layer — stem + dot at (x, y) positions. (lay-lollipop views) — add to views (lay-lollipop views {:color :group}) — colored stems

(-> sales
    (sk/lay-lollipop :product :revenue))
revenueproduct:widget:gadget:gizmo:doohickey050100150200250300350

lay-tile

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a tile/heatmap layer — filled rectangles colored by value. (lay-tile views) — 2D binned heatmap (lay-tile views {:fill :value}) — pre-computed fill values

(-> data/iris
    (sk/lay-tile :sepal_length :sepal_width))
sepal widthsepal length4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

lay-density2d

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a 2D density layer — KDE-smoothed heatmap. (lay-density2d views) — add to views (lay-density2d views {:kde2d-grid 40}) — finer grid resolution

(-> data/iris
    (sk/lay-density2d :sepal_length :sepal_width))
sepal widthsepal length3.03.54.04.55.05.56.06.57.07.58.08.59.01.52.02.53.03.54.04.55.0

lay-contour

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a contour layer — iso-density contour lines from 2D KDE. (lay-contour views) — add to views (lay-contour views {:levels 8}) — custom iso-levels

(-> data/iris
    (sk/lay-contour :sepal_length :sepal_width))
sepal widthsepal length3.03.54.04.55.05.56.06.57.07.58.08.59.01.52.02.53.03.54.04.55.0

lay-ridgeline

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a ridgeline layer — vertically stacked density curves per category. (lay-ridgeline views) — add to views (lay-ridgeline views {:color :species}) — colored ridgelines

(-> data/iris
    (sk/lay-ridgeline :species :sepal_length))
speciessepal length456789setosaversicolorvirginica

lay-rug

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a rug layer — tick marks along axis margins. (lay-rug views) — ticks on x-axis (lay-rug views {:side :both}) — ticks on both axes

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width)
    (sk/lay-rug {:side :both}))
sepal widthsepal length4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

lay-step

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a step layer — horizontal-then-vertical connected points. (lay-step views) — add to views (lay-step views {:color :group}) — with options (lay-step data :x :y) — from data

(-> tiny
    (sk/lay-step :x :y)
    sk/lay-point)
yx1.01.52.02.53.03.54.04.55.01.01.52.02.53.03.54.04.55.0

lay-summary

[views]

[views-or-data x-or-opts]

[data x y-or-opts]

[data x y opts]

Add a summary layer — mean ± standard error per category. (lay-summary views) — add to views (lay-summary views {:color :species}) — per-group summary

(-> data/iris
    (sk/lay-summary :species :sepal_length))
sepal lengthspeciessetosaversicolorvirginica5.05.25.45.65.86.06.26.46.6

Rendering

plot

[sketch-or-views]

[sketch-or-views opts]

Render views as a figure (default: SVG hiccup wrapped with kind/hiccup). (plot views) — default 600×400 SVG (plot views {:width 800 :height 500 :title “My Plot”}) (plot views {:format :svg}) — explicit format Options: :width, :height, :title, :subtitle, :caption, :x-label, :y-label, :palette (keyword, vector, or map), :theme {:bg :grid :font-size}, :legend-position (:right :bottom :top :none), :tooltip, :brush, :color-scale (:sequential, :diverging, or {:low :mid :high} map), :color-midpoint (number — centers diverging gradient on this value), :validate (default true — validates plan against Malli schema).

See the Customization notebook for options (title, theme, tooltip, brush, legend position, palette).

(-> tiny
    (sk/lay-point :x :y))
yx1.01.52.02.53.03.54.04.55.01.01.52.02.53.03.54.04.55.0

options

[sketch-or-views opts]

Set plot-level options on a sketch. Options are deep-merged — nested maps like :theme are merged recursively. (options sketch {:width 800 :palette :dark2}) (options sketch {:theme {:bg “#FFF”} :legend-position :bottom})

Set render options on a sketch:

(-> tiny
    (sk/lay-point :x :y)
    (sk/options {:width 400 :height 200 :title "Small Plot"}))
Small Plotyx1234524

sketch?

[x]

Return true if x is a Sketch (auto-rendering sketch).

Check whether a value is a sketch:

(sk/sketch? (sk/lay-point tiny :x :y))
true

views-of

[sketch-or-views]

Extract the raw views vector from a sketch. Useful for inspecting view data: (kind/pprint (views-of my-sketch))

Extract the raw views from a sketch:

(count (sk/views-of (-> tiny (sk/lay-point :x :y) (sk/lay-lm))))
2

plan

[sketch-or-views]

[sketch-or-views opts]

Resolve views into a plan — a plain Clojure map with data-space geometry, domains, tick info, legend, and layout. No membrane types, no datasets, no scale objects in the output. Serializable data. (plan views) — default 600×400 (plan views {:width 800 :title “My Plot”}) Pass {:validate false} to skip Malli schema validation.

Returns the intermediate plan data structure:

(def sk1 (-> tiny
             (sk/lay-point :x :y)
             sk/plan))
sk1
{:panels
 [{:coord :cartesian,
   :y-domain [0.8 5.2],
   :x-scale {:type :linear},
   :x-domain [0.8 5.2],
   :x-ticks
   {:values [1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0],
    :labels ["1.0" "1.5" "2.0" "2.5" "3.0" "3.5" "4.0" "4.5" "5.0"],
    :categorical? false},
   :col 0,
   :layers
   [{:mark :point,
     :style {:opacity 0.75, :radius 3.0},
     :groups
     [{:color [0.2 0.2 0.2 1.0], :xs #tech.v3.dataset.column<int64>[5]
:x
[1, 2, 3, 4, 5], :ys #tech.v3.dataset.column<int64>[5]
:y
[2, 4, 1, 5, 3], :row-indices #tech.v3.dataset.column<int64>[5]
:__row-idx
[0, 1, 2, 3, 4]}],
     :y-domain [1 5],
     :x-domain [1 5]}],
   :y-scale {:type :linear},
   :y-ticks
   {:values [1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0],
    :labels ["1.0" "1.5" "2.0" "2.5" "3.0" "3.5" "4.0" "4.5" "5.0"],
    :categorical? false},
   :row 0}],
 :width 600,
 :height 400,
 :caption nil,
 :total-width 622.5,
 :legend-position :right,
 :layout-type :single,
 :layout
 {:subtitle-pad 0,
  :legend-w 0,
  :caption-pad 0,
  :y-label-pad 22.5,
  :legend-h 0,
  :title-pad 0,
  :strip-h 0,
  :x-label-pad 18,
  :strip-w 0},
 :grid {:rows 1, :cols 1},
 :legend nil,
 :panel-height 400.0,
 :title nil,
 :y-label "y",
 :alpha-legend nil,
 :x-label "x",
 :subtitle nil,
 :panel-width 600.0,
 :size-legend nil,
 :total-height 418.0,
 :margin 30}

Pipeline

views->plan

[sketch-or-views]

[sketch-or-views opts]

Convert views into a plan — a plain Clojure map with data-space geometry, domains, tick info, legend, and layout. No membrane types, no datasets, no scale objects in the output. Serializable data. Same as plan but with an explicit pipeline-style name. (views->plan views) — default 600×400 (views->plan views {:width 800 :title “My Plot”}) Pass {:validate false} to skip Malli schema validation.

(def sk2 (-> tiny
             (sk/lay-point :x :y)
             sk/views->plan))
(= (keys sk1) (keys sk2))
true

plan->membrane

[plan-data & {:as opts}]

Convert a plan into a membrane drawable tree. (plan->membrane (plan sketch))

(def m1 (sk/plan->membrane sk1))
(vector? m1)
true

membrane->figure

[membrane-tree format opts]

Convert a membrane drawable tree into a figure for the given format. Dispatches on format keyword; :svg is always available. (membrane->figure (plan->membrane (plan views)) :svg {})

(first (sk/membrane->figure m1 :svg
                            {:total-width (:total-width sk1)
                             :total-height (:total-height sk1)}))
:svg

plan->figure

[plan format opts]

Convert a plan into a figure for the given format. Dispatches on format keyword. Each renderer is a separate namespace that registers a defmethod; :svg is always available. (plan->figure (plan sketch) :svg {}) (plan->figure (plan sketch) :plotly {})

(first (sk/plan->figure sk1 :svg {}))
:svg

Transforms

coord

[sketch-or-views c]

Set coordinate system on views. Options: :cartesian (default), :flip, :polar, :fixed. (coord views :flip) — flipped coordinates (coord views :fixed) — fixed 1:1 aspect ratio

Flip axes:

(-> data/iris
    (sk/lay-bar :species) (sk/coord :flip))
species05101520253035404550setosaversicolorvirginica

Polar coordinates:

(-> data/iris
    (sk/lay-bar :species) (sk/coord :polar))

scale

[sketch-or-views channel type-or-opts]

[sketch-or-views channel type opts]

Set scale options for :x or :y across all views. (scale views :x :log) — log x-axis (scale views :y {:type :linear :domain [0 100]}) — fixed domain

Log scale:

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width) (sk/scale :x :log))
sepal widthsepal length52.02.53.03.54.04.5

Fixed domain:

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width) (sk/scale :x {:domain [3 9]}))
sepal widthsepal length3.03.54.04.55.05.56.06.57.07.58.08.59.02.02.53.03.54.04.5

Annotations

rule-v

[intercept]

Vertical reference line at x = intercept. (rule-v 5) — line at x=5

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width) (sk/lay (sk/rule-v 6.0)))
sepal widthsepal length4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

rule-h

[intercept]

Horizontal reference line at y = intercept. (rule-h 3) — line at y=3

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width) (sk/lay (sk/rule-h 3.0)))
sepal widthsepal length4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

band-v

[lo hi]

[lo hi opts]

Vertical shaded band from x = lo to x = hi. (band-v 4 6) — shaded region between x=4 and x=6 (band-v 4 6 {:alpha 0.3}) — with custom opacity

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width) (sk/lay (sk/band-v 5.5 6.5)))
sepal widthsepal length4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

band-h

[lo hi]

[lo hi opts]

Horizontal shaded band from y = lo to y = hi. (band-h 2 4) — shaded region between y=2 and y=4 (band-h 2 4 {:alpha 0.3}) — with custom opacity

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width) (sk/lay (sk/band-h 2.5 3.5)))
sepal widthsepal length4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

Utilities

cross

[xs ys]

Cartesian product of two sequences.

(sk/cross [:a :b] [1 2 3])
([:a 1] [:a 2] [:a 3] [:b 1] [:b 2] [:b 3])
(-> data/iris
    (sk/view (sk/cross [:sepal_length :petal_length]
                       [:sepal_width :petal_width]))
    (sk/lay-point {:color :species}))
speciessetosaversicolorvirginica234680125sepal lengthpetal lengthsepal widthpetal width

distribution

[data & cols]

Create diagonal views (x=y) for each column, used for histograms in SPLOM. (distribution data :a :b :c) => views with [[:a :a] [:b :b] [:c :c]]

(-> (sk/distribution data/iris :sepal_length :sepal_width)
    sk/lay-histogram)
01020234sepal lengthsepal widthsepal lengthsepal width

Faceting

facet

[sketch-or-views col]

[sketch-or-views col direction]

Split views by a categorical column into separate panels. Default is a horizontal row of panels. (facet views :species) — horizontal row (facet views :species :col) — vertical column

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width {:color :species})
    (sk/facet :species))
sepal widthsepal lengthspeciessetosaversicolorvirginica682.02.53.03.54.04.56868setosaversicolorvirginica

facet-grid

[sketch-or-views row-col col-col]

Split views by two categorical columns for a row × column grid. Either column may be nil for a single-dimension facet. (facet-grid views :smoker :sex) — 2D grid (facet-grid views nil :species) — same as facet

(-> data/tips
    (sk/lay-point :total_bill :tip {:color :sex})
    (sk/facet-grid :smoker :sex))
tiptotal billsexFemaleMale51010203040505101020304050FemaleMaleNoYes

Inspection

svg-summary

[svg-or-sketch]

[svg-or-sketch theme]

Extract structural summary from SVG hiccup for testing. Returns a map with :width, :height, :panels, :points, :lines, :polygons, :tiles, :visible-tiles, and :texts — useful for asserting plot structure. Accepts SVG hiccup or a Sketch (auto-renders to SVG first). (svg-summary (plot views)) — summary of rendered SVG (svg-summary my-sketch) — auto-renders Sketch, then summarizes

(-> data/iris
    (sk/lay-point :sepal_length :sepal_width {:color :species}) sk/svg-summary)
{:texts
 ["sepal width"
  "sepal length"
  "species"
  "setosa"
  "versicolor"
  "virginica"
  "4.5"
  "5.0"
  "5.5"
  "6.0"
  "6.5"
  "7.0"
  "7.5"
  "8.0"
  "2.0"
  "2.5"
  "3.0"
  "3.5"
  "4.0"
  "4.5"],
 :width 722.5,
 :lines 0,
 :points 150,
 :tiles 0,
 :polygons 0,
 :visible-tiles 0,
 :panels 1,
 :height 418.0}

valid-plan?

[plan]

Check if a plan conforms to the Malli schema. (valid-plan? (plan views)) — true if valid

(sk/valid-plan? sk1)
true

explain-plan

[plan]

Explain why a plan does not conform to the Malli schema. Returns nil if valid, or a Malli explanation map if invalid. (explain-plan (plan views))

(sk/explain-plan sk1)
nil

Configuration

config

[]

Return the effective resolved configuration as a map. Merges: library defaults < napkinsketch.edn < set-config! < config. Useful for inspecting which values are in effect. (config) — show current resolved config

(sk/config)
{:margin-multi 30,
 :validate true,
 :point-stroke "none",
 :title-offset 18,
 :tick-spacing-y 40,
 :panel-size 200,
 :label-offset 18,
 :label-font-size 13,
 :default-color "#333",
 :width 600,
 :point-stroke-width 0,
 :annotation-dash [4 3],
 :legend-width 100,
 :theme {:bg "#E8E8E8", :grid "#F5F5F5", :font-size 11},
 :bin-method :sturges,
 :domain-padding 0.05,
 :strip-height 16,
 :point-opacity 0.75,
 :line-width 2.5,
 :grid-stroke-width 0.6,
 :tick-spacing-x 60,
 :strip-font-size 10,
 :title-font-size 15,
 :band-opacity 0.15,
 :bar-opacity 0.85,
 :annotation-stroke "#333",
 :height 400,
 :margin 30,
 :point-radius 3.0}

set-config!

[m]

Set global config overrides. Persists across calls until reset. (set-config! {:palette :dark2 :theme {:bg “#FFFFFF”}}) (set-config! nil) — reset to defaults

with-config

[config-map & body]

Execute body with thread-local config overrides. Overrides take precedence over set-config! and defaults, but plot options still win. (with-config {:theme {:bg “#FFF”}} (plot …))

(sk/with-config {:palette :pastel1}
  (:palette (sk/config)))
:pastel1

Documentation Metadata

Three maps document the option keys at each scope level.

config-key-docs

Documentation metadata for configuration keys. Maps each config key to [category description]. Use with (sk/config) to build reference tables.

(count sk/config-key-docs)
36

plot-option-docs

Documentation for plot-level option keys. These are accepted by sk/options, sk/plan, and sk/plot but are inherently per-plot (text content or nested config override). Maps each key to [category description].

(count sk/plot-option-docs)
6

layer-option-docs

Documentation for layer option keys accepted by lay- functions. Maps each key to a description string.

(count sk/layer-option-docs)
20

Method Registry

method-lookup

[k]

Look up a registered method by keyword. Returns the method map (with :mark, :stat, :position, :doc), or nil if not found. (method-lookup :histogram) => {:mark :bar, :stat :bin, …}

(sk/method-lookup :lm)
{:mark :line,
 :stat :lm,
 :accepts [:se :size :nudge-x :nudge-y],
 :doc
 "Linear model (lm) — ordinary least squares (OLS) regression line."}

method-registered

[]

Return all registered methods as a map of keyword → method map. Useful for generating documentation tables.

(count (sk/method-registered))
25

Documentation Helpers

Query the self-documenting dispatch tables for any extensible concept.

stat-doc

[k]

Return the prose description for a stat keyword. Returns “(no description)” if no [:key :doc] defmethod is registered. (stat-doc :bin) => “Bin numerical values into ranges”

(sk/stat-doc :lm)
"Linear model (lm) — OLS regression line + optional confidence band"

mark-doc

[k]

Return the prose description for a mark keyword. Returns “(no description)” if no [:key :doc] defmethod is registered. (mark-doc :point) => “Filled circle”

(sk/mark-doc :point)
"Filled circle"

position-doc

[k]

Return the prose description for a position keyword. Returns “(no description)” if no [:key :doc] defmethod is registered. (position-doc :dodge) => “Shift groups side-by-side within a band”

(sk/position-doc :dodge)
"Shift groups side-by-side within a band"

scale-doc

[k]

Return the prose description for a scale keyword. Returns “(no description)” if no [:key :doc] defmethod is registered. (scale-doc :linear) => “Continuous linear mapping”

(sk/scale-doc :linear)
"Continuous linear mapping"

coord-doc

[k]

Return the prose description for a coordinate type keyword. Returns “(no description)” if no [:key :doc] defmethod is registered. (coord-doc :polar) => “Radial mapping: x→angle, y→radius”

(sk/coord-doc :cartesian)
"Standard x-right, y-up mapping"

membrane-mark-doc

[k]

Return the prose description for how a mark renders to membrane drawables. Returns “(no description)” if no [:key :doc] defmethod is registered. (membrane-mark-doc :point) => “Translated colored rounded-rectangles”

(sk/membrane-mark-doc :point)
"Translated colored rounded-rectangles"

Composition

arrange

[plots]

[plots opts]

Arrange multiple plots in a CSS grid layout. plots: a flat vector of plots or Sketches, or a vector of vectors (explicit rows). opts: {:cols N, :title “…”, :gap “8px”}. (arrange [plot-a plot-b]) — 1×2 row (arrange [plot-a plot-b plot-c] {:cols 2}) — 2-column grid, wraps (arrange [[plot-a plot-b] [plot-c plot-d]]) — explicit 2×2 grid

(sk/arrange [(-> data/iris
                 (sk/lay-point :sepal_length :sepal_width {:color :species}) (sk/options {:width 250 :height 200}))
             (-> data/iris
                 (sk/lay-point :petal_length :petal_width {:color :species}) (sk/options {:width 250 :height 200}))]
            {:cols 2})
sepal widthsepal lengthspeciessetosaversicolorvirginica5678234petal widthpetal lengthspeciessetosaversicolorvirginica246012

Export

save

[sketch-or-views path]

[sketch-or-views path opts]

Save a plot to an SVG file. views — a vector of view maps, or a Sketch. path — file path (string or java.io.File). opts — same options as plot (:width, :height, :title, :theme, etc.). Tooltip and brush interactivity are not included in saved files. Returns the path. (save views “plot.svg”) (save views “plot.svg” {:width 800 :height 600})

Save a plot to an SVG file:

(let [path (str (java.io.File/createTempFile "napkinsketch-example" ".svg"))]
  (sk/save (-> data/iris (sk/lay-point :sepal_length :sepal_width {:color :species}))
           path
           {:title "Iris Export"})
  (.contains (slurp path) "<svg"))
true
source: notebooks/napkinsketch_book/api_reference.clj