27  Data functions: sets and series

Functions turning set memberships and time series into rows for ordinary plots: the bars and dot matrix of an UpSet plot, lag pairs, autocorrelation rows and the folded bands of a horizon chart. The builders plot/acf and plot/horizon (Builders: series) draw the last two directly.

(ns reference.data-sets-series
  (:require [fastmath.core :as m]
            [fastmath.random :as r]
            [cljplot2.chart :as chart]
            [cljplot2.core :as plot]
            [cljplot2.data.series :as series]
            [cljplot2.data.sets :as sets]
            [cljplot2.describe :as describe]
            [notebook-utils :as nu]))

Set memberships: one row per item and set it belongs to (an item may be in several).

(def members (concat (for [i (range 40)] {:set "coffee" :item i})
                     (for [i (range 25 60)] {:set "tea" :item i})
                     (for [i (range 30 45)] {:set "juice" :item i})
                     (for [i (range 55 70)] {:set "juice" :item i})))
set item
coffee 0
coffee 1
coffee 2
coffee 3
coffee 4
coffee 5
coffee 6
coffee 7
coffee 8
coffee 9
coffee 10
coffee 11
coffee 12
coffee 13
coffee 14
coffee 15
coffee 16
coffee 17
coffee 18
coffee 19
coffee 20
coffee 21
coffee 22
coffee 23
coffee 24
coffee 25
coffee 26
coffee 27
coffee 28
coffee 29
coffee 30
coffee 31
coffee 32
coffee 33
coffee 34
coffee 35
coffee 36
coffee 37
coffee 38
coffee 39
tea 25
tea 26
tea 27
tea 28
tea 29
tea 30
tea 31
tea 32
tea 33
tea 34
tea 35
tea 36
tea 37
tea 38
tea 39
tea 40
tea 41
tea 42
tea 43
tea 44
tea 45
tea 46
tea 47
tea 48
tea 49
tea 50
tea 51
tea 52
tea 53
tea 54
tea 55
tea 56
tea 57
tea 58
tea 59
juice 30
juice 31
juice 32
juice 33
juice 34
juice 35
juice 36
juice 37
juice 38
juice 39
juice 40
juice 41
juice 42
juice 43
juice 44
juice 55
juice 56
juice 57
juice 58
juice 59
juice 60
juice 61
juice 62
juice 63
juice 64
… …

A seeded autoregressive series with a weekly bump:

(def weekly (let [g (r/rng :mersenne 8)]
              (vec (reductions (fn [y t] (+ (* 0.6 (double y)) (* 2.0 (m/sin (* m/TWO_PI (/ (double t) 7.0))))
                                            (r/grandom g)))
                               0.0 (range 1 200)))))
t y
0 0.0
1 0.13977307440775744
2 2.7905276303712556
3 1.182076374268736
4 1.8857619600375348
5 0.17450253670221405
6 -2.2114471052072315
7 -3.044028051154591
8 -0.14976638399572134
9 1.587846819931787
10 2.2795328370428445
11 -0.2956701822523501
12 -2.5970802695960344
13 -1.0628029490748316
14 -1.3726235623170633
15 2.2752608361156237
16 4.716331163150285
17 4.738859355206512
18 2.7516193587370803
19 -0.96089041389926
20 -1.672460418656026
21 -1.5837748276209425
22 0.248029734088489
23 2.1266466663341697
24 2.3667789741884153
25 -0.5284470837340532
26 -2.5067655285740633
27 -2.27184448699434
28 -1.0744854689699892
29 1.0992257725118908
30 2.297817519004787
31 2.524555509699196
32 0.9066650336613162
33 -1.973900083417808
34 -1.4715527312854013
35 -0.7397028802799019
36 1.3943372501425042
37 3.195325772326656
38 2.4796323879573707
39 0.3573983588652897
40 -0.20454515634164205
41 -0.9842152462781779
42 -1.2190757467223128
43 -0.473279449134298
44 0.5609960602226269
45 0.5857249817586214
46 1.2275317907812817
47 -1.6392350408707481
48 -2.5724035266084746
49 -0.7405028134931776
50 1.7074340387731763
51 2.594161614240549
52 2.3498598156391473
53 2.107735039246341
54 -1.1114637386859947
55 -3.3690149153531386
56 -1.7592885604742825
57 0.9813141171195396
58 2.116997285412064
59 1.8054651816902145
60 -0.14654679116113023
61 -0.9156730593091467
62 -1.789270135872337
63 -2.4440122834623805
64 0.3406167504738572
65 2.3845853192163005
66 -0.0032829913925178644
67 -1.0969826276179542
68 -3.5429896124502265
69 -4.4024603131052045
70 -1.6091605047216901
71 1.1039566123281377
72 0.7408238747971894
73 2.512389179049876
74 1.8324044134757314
75 -1.3966767543311789
76 -3.4027521255237416
77 -2.5387986049782447
78 1.5168243927789171
79 2.697994178390557
80 4.341639710378089
81 3.471117571811411
82 -0.6374184324025643
83 -3.144668234807061
84 -2.1590227155889243
85 -0.3249893795694875
86 1.6319504527117272
87 0.9181483544698612
88 -0.9042325628070139
89 -3.1302798909817056
90 -3.831753173127805
91 -4.033743121508569
92 -1.3156557235924389
93 1.160997527709536
94 0.69073209315031
95 -1.9516737852939403
96 -3.1029627017329986
97 -3.9880277285668617
98 -1.4921477136546932
99 1.0212389935099315
… …

27.1 sets/upset-rows

The bars of an UpSet plot: every combination of sets that holds items exclusively - its sets, size and degree - by size descending. The mapping names the set and item keys; a third argument chooses (and orders) the sets.

combination sets size degree
coffee ["coffee"] 25 1
tea ["tea"] 10 1
juice ["juice"] 10 1
tea & juice ["tea" "juice"] 10 2
coffee & tea & juice ["coffee" "tea" "juice"] 10 3
coffee & tea ["coffee" "tea"] 5 2

27.2 sets/membership-rows

The dot matrix under the bars: a row per combination and set, :member? true where the set is in the combination.

combination set member?
coffee coffee true
coffee tea false
coffee juice false
tea coffee false
tea tea true
tea juice false
juice coffee false
juice tea false
juice juice true
tea & juice coffee false
tea & juice tea true
tea & juice juice true
coffee & tea & juice coffee true
coffee & tea & juice tea true
coffee & tea & juice juice true
coffee & tea coffee true
coffee & tea tea true
coffee & tea juice false

Together, an UpSet plot of two stacked plots - the bars, then the dots of the members over grey dots of every cell - here with the sets chosen and ordered (tea first):

(plot/render-image (plot/arrange [{:data (sets/upset-rows members {:set :set :item :item} ["tea" "coffee" "juice"])
                                   :mapping {:x :combination :y :size}
                                   :charts [(chart/bar {:value-label true})]
                                   :labels {:x nil :y "items"}}
                                  {:data (sets/membership-rows members {:set :set :item :item} ["tea" "coffee" "juice"])
                                   :mapping {:x :combination :y :set}
                                   :charts [(chart/scatter {:size 12 :color [210 210 210]})
                                            (chart/scatter {:data (filter :member? (sets/membership-rows members {:set :set :item :item}
                                                                                                         ["tea" "coffee" "juice"]))
                                                            :size 12 :color :black})]
                                   :scales {:y {:reverse true}}
                                   :labels {:x nil :y nil}}]
                                 {:columns 1 :heights [2 1]})
                   {:width 900 :height 450})

27.3 series/lag-rows

Pairs every value y(t) with y(t + k) - a lag plot shows the correlation at lag k (here the weekly cycle: strong at 7, negative at 3):

t x y
0 0.0 -3.044028051154591
1 0.13977307440775744 -0.14976638399572134
2 2.7905276303712556 1.587846819931787
3 1.182076374268736 2.2795328370428445
4 1.8857619600375348 -0.2956701822523501
5 0.17450253670221405 -2.5970802695960344
6 -2.2114471052072315 -1.0628029490748316
7 -3.044028051154591 -1.3726235623170633
8 -0.14976638399572134 2.2752608361156237
9 1.587846819931787 4.716331163150285
10 2.2795328370428445 4.738859355206512
11 -0.2956701822523501 2.7516193587370803
12 -2.5970802695960344 -0.96089041389926
13 -1.0628029490748316 -1.672460418656026
14 -1.3726235623170633 -1.5837748276209425
15 2.2752608361156237 0.248029734088489
16 4.716331163150285 2.1266466663341697
17 4.738859355206512 2.3667789741884153
18 2.7516193587370803 -0.5284470837340532
19 -0.96089041389926 -2.5067655285740633
20 -1.672460418656026 -2.27184448699434
21 -1.5837748276209425 -1.0744854689699892
22 0.248029734088489 1.0992257725118908
23 2.1266466663341697 2.297817519004787
24 2.3667789741884153 2.524555509699196
25 -0.5284470837340532 0.9066650336613162
26 -2.5067655285740633 -1.973900083417808
27 -2.27184448699434 -1.4715527312854013
28 -1.0744854689699892 -0.7397028802799019
29 1.0992257725118908 1.3943372501425042
30 2.297817519004787 3.195325772326656
31 2.524555509699196 2.4796323879573707
32 0.9066650336613162 0.3573983588652897
33 -1.973900083417808 -0.20454515634164205
34 -1.4715527312854013 -0.9842152462781779
35 -0.7397028802799019 -1.2190757467223128
36 1.3943372501425042 -0.473279449134298
37 3.195325772326656 0.5609960602226269
38 2.4796323879573707 0.5857249817586214
39 0.3573983588652897 1.2275317907812817
40 -0.20454515634164205 -1.6392350408707481
41 -0.9842152462781779 -2.5724035266084746
42 -1.2190757467223128 -0.7405028134931776
43 -0.473279449134298 1.7074340387731763
44 0.5609960602226269 2.594161614240549
45 0.5857249817586214 2.3498598156391473
46 1.2275317907812817 2.107735039246341
47 -1.6392350408707481 -1.1114637386859947
48 -2.5724035266084746 -3.3690149153531386
49 -0.7405028134931776 -1.7592885604742825
50 1.7074340387731763 0.9813141171195396
51 2.594161614240549 2.116997285412064
52 2.3498598156391473 1.8054651816902145
53 2.107735039246341 -0.14654679116113023
54 -1.1114637386859947 -0.9156730593091467
55 -3.3690149153531386 -1.789270135872337
56 -1.7592885604742825 -2.4440122834623805
57 0.9813141171195396 0.3406167504738572
58 2.116997285412064 2.3845853192163005
59 1.8054651816902145 -0.0032829913925178644
60 -0.14654679116113023 -1.0969826276179542
61 -0.9156730593091467 -3.5429896124502265
62 -1.789270135872337 -4.4024603131052045
63 -2.4440122834623805 -1.6091605047216901
64 0.3406167504738572 1.1039566123281377
65 2.3845853192163005 0.7408238747971894
66 -0.0032829913925178644 2.512389179049876
67 -1.0969826276179542 1.8324044134757314
68 -3.5429896124502265 -1.3966767543311789
69 -4.4024603131052045 -3.4027521255237416
70 -1.6091605047216901 -2.5387986049782447
71 1.1039566123281377 1.5168243927789171
72 0.7408238747971894 2.697994178390557
73 2.512389179049876 4.341639710378089
74 1.8324044134757314 3.471117571811411
75 -1.3966767543311789 -0.6374184324025643
76 -3.4027521255237416 -3.144668234807061
77 -2.5387986049782447 -2.1590227155889243
78 1.5168243927789171 -0.3249893795694875
79 2.697994178390557 1.6319504527117272
80 4.341639710378089 0.9181483544698612
81 3.471117571811411 -0.9042325628070139
82 -0.6374184324025643 -3.1302798909817056
83 -3.144668234807061 -3.831753173127805
84 -2.1590227155889243 -4.033743121508569
85 -0.3249893795694875 -1.3156557235924389
86 1.6319504527117272 1.160997527709536
87 0.9181483544698612 0.69073209315031
88 -0.9042325628070139 -1.9516737852939403
89 -3.1302798909817056 -3.1029627017329986
90 -3.831753173127805 -3.9880277285668617
91 -4.033743121508569 -1.4921477136546932
92 -1.3156557235924389 1.0212389935099315
93 1.160997527709536 3.4969528572060113
94 0.69073209315031 2.1886345245865
95 -1.9516737852939403 -0.8157697847877093
96 -3.1029627017329986 -2.7192455186430973
97 -3.9880277285668617 -4.868280462395595
98 -1.4921477136546932 -1.731832964844711
99 1.0212389935099315 -1.2620284015534728
… … …
(plot/render-image (plot/arrange [{:data (series/lag-rows weekly 3)
                                   :mapping {:x :x :y :y}
                                   :charts [(chart/scatter {:size 5})]
                                   :labels {:title "lag 3" :x "y(t)" :y "y(t+3)"}}
                                  {:data (series/lag-rows weekly 7)
                                   :mapping {:x :x :y :y}
                                   :charts [(chart/scatter {:size 5})]
                                   :labels {:title "lag 7" :x "y(t)" :y "y(t+7)"}}]
                                 {:columns 2})
                   {:width 800 :height 380})

27.4 series/acf-rows

The autocorrelation function: a row per lag with its value, the significance band and whether the value is outside it; :partial? true - the partial autocorrelation.

Option Type Default Description
:lags a positive integer or nil floor(10 log10 n), at most n - 1 (R acf) the largest lag, from 1 to n - 1 for n values
:alpha a number in (0 1) or nil 0.05 significance level of the band (0.05 - a 95% band)
:partial? true or false or nil false the partial autocorrelation (lags from 1, a constant band) instead of the autocorrelation
lag value lo hi significant?
0 1.0 -0.13859038243496777 0.13859038243496777 false
1 0.6215962877171711 -0.1845264138478444 0.1845264138478444 true
2 -0.0245812762532376 -0.18458929818755346 0.18458929818755346 false
3 -0.5117536249216397 -0.2100801599517992 0.2100801599517992 true
4 -0.5330153237806908 -0.23462195777800635 0.23462195777800635 true
5 -0.10108379768907899 -0.23545696168192612 0.23545696168192612 false
6 0.44682475423704965 -0.25121613012862887 0.25121613012862887 true
7 0.6837820669513154 -0.2847289743030383 0.2847289743030383 true
8 0.4286047930660557 -0.2968626418517464 0.2968626418517464 true
9 -0.13943006698959823 -0.29811782282562116 0.29811782282562116 false
10 -0.5932087660505585 -0.3199878135302573 0.3199878135302573 true

Drawn by hand from the rows - segments to 0, the band as a ribbon, significant lags in red: the autocorrelation up to lag 21 at the default 95% band (left) and the partial one with a 99% band (right):

(plot/render-image (plot/arrange [{:data (series/acf-rows weekly {:lags 21 :alpha 0.05})
                                   :mapping {:x :lag :y :value :ymin :lo :ymax :hi}
                                   :charts [(chart/ribbon {:color [69 117 180] :alpha 0.15})
                                            (chart/segment {:yend 0 :width 2})
                                            (chart/scatter {:mapping {:color #(if (:significant? %) "yes" "no")}})]
                                   :scales {:color {:domain ["no" "yes"] :range [[90 90 90] [200 40 40]]
                                                    :title "significant"}}
                                   :labels {:title "ACF, 95% band"}
                                   :legend false}
                                  {:data (series/acf-rows weekly {:lags 21 :alpha 0.01 :partial? true})
                                   :mapping {:x :lag :y :value :ymin :lo :ymax :hi}
                                   :charts [(chart/ribbon {:color [69 117 180] :alpha 0.15})
                                            (chart/segment {:yend 0 :width 2})
                                            (chart/scatter {:mapping {:color #(if (:significant? %) "yes" "no")}})]
                                   :scales {:color {:domain ["no" "yes"] :range [[90 90 90] [200 40 40]]
                                                    :title "significant"}}
                                   :labels {:title "PACF, :alpha 0.01"}}]
                                 {:columns 2 :widths [1 1.3]})
                   {:width 1000 :height 340})

27.5 series/horizon-rows

The bands of a horizon chart: values folded into :bands bands of one height, negatives mirrored upward as negative band numbers; returns {:rows [...] :band-height h}.

Option Type Default Description
:x keyword or string :x row key of the x values (numbers)
:y keyword or string :y row key of the y values (finite numbers, nil breaks the bands)
:series keyword or string or nil none - one series row key of the series, one horizon per value in first-appearance order
:bands a positive integer 2 number of bands each sign of the values is folded into
:band-height a positive finite number or nil the largest |y| of all series / :bands (1 when it is 0) height of one band in y units
:interpolator a fastmath 1D interpolation method keyword or a function (fn [xs ys & params] f) or nil none - straight segments a curve the valid points of every run are resampled on before folding
:steps-per-gap a positive integer 10 resampled points per gap between consecutive x (with :interpolator)
(def temperatures (for [city ["Oslo" "Rome"] day (range 60)]
                    {:city city :day day
                     :anomaly (* (if (= city "Oslo") 4.0 2.5) (m/sin (+ (* 0.12 day) (if (= city "Oslo") 0.0 1.5))))}))
city day anomaly
Oslo 0 0.0
Oslo 1 0.47884882915567745
Oslo 2 0.9508105057085383
Oslo 3 1.4090969331003598
Oslo 4 1.8471167021659316
Oslo 5 2.2585698935801415
Oslo 6 2.6375386878858924
Oslo 7 2.978572479883437
Oslo 8 3.276766273203993
Oslo 9 3.52783122753979
Oslo 10 3.728156343868905
Oslo 11 3.874860400473061
Oslo 12 3.9658333927667457
Oslo 13 3.999766880919865
Oslo 14 3.976172808792304
Oslo 15 3.895390523512781
Oslo 16 3.7585818947412997
Oslo 17 3.5677146038135183
Oslo 18 3.3255338431147323
Oslo 19 3.035522832723688
Oslo 20 2.701852722204604
Oslo 21 2.3293225980963275
Oslo 22 1.9232904599545946
Oslo 23 1.4895961577002228
Oslo 24 1.0344773986444433
Oslo 25 0.5644800322394689
Oslo 26 0.08636390290438384
Oslo 27 -0.392994374980433
Oslo 28 -0.8667003215495185
Oslo 29 -1.3279407528829363
Oslo 30 -1.7700817731794083
Oslo 31 -2.1867641882771474
Oslo 32 -2.5719949682156353
Oslo 33 -2.920233443357198
Oslo 34 -3.226470994332962
Oslo 35 -3.4863030896543528
Oslo 36 -3.6959926348927516
Oslo 37 -3.852523722293266
Oslo 38 -3.953645007756522
Oslo 39 -3.997902091309136
Oslo 40 -3.9846584353433627
Oslo 41 -3.914104519764554
Oslo 42 -3.7872551023704357
Oslo 43 -3.6059346238654193
Oslo 44 -3.372750967425669
Oslo 45 -3.091057950223951
Oslo 46 -2.7649070863885084
Oslo 47 -2.398989315176175
Oslo 48 -1.9985675324676098
Oslo 49 -1.5694008959658154
Oslo 50 -1.1176619927957034
Oslo 51 -0.6498480608606167
Oslo 52 -0.17268754083491472
Oslo 53 0.3069566971700721
Oslo 54 0.7821860604021735
Oslo 55 1.2461654540535114
Oslo 56 1.6922215885719873
Oslo 57 2.113938959771723
Oslo 58 2.5052521212866234
Oslo 59 2.8605329222374314
Rome 0 2.493737466510136
Rome 1 2.49697435867631
Rome 2 2.464297947088884
Rome 3 2.3961782076972855
Rome 4 2.2935948882045247
Rome 5 2.1580234166221843
Rome 6 1.991413680590217
Rome 7 1.7961619826728157
Rome 8 1.5750765749897306
Rome 9 1.3313372688890528
Rome 10 1.0684497005845746
Rome 11 0.7901949105426345
Rome 12 0.5005749618044263
Rome 13 0.2037553794006728
Rome 14 -0.09599476126308734
Rome 15 -0.39436423535812054
Rome 16 -0.6870616758078101
Rome 17 -0.9698772948543257
Rome 18 -1.2387434322921123
Rome 19 -1.4897930595194098
Rome 20 -1.7194153979599345
Rome 21 -1.9243078519100596
Rome 22 -2.1015235088754864
Rome 23 -2.248513524212944
Rome 24 -2.3631637804701584
Rome 25 -2.4438252941627425
Rome 26 -2.4893379326556135
Rome 27 -2.4990471000354635
Rome 28 -2.4728131519859247
Rome 29 -2.411013404253826
Rome 30 -2.3145367058193314
Rome 31 -2.184770654822556
Rome 32 -2.0235816411165484
Rome 33 -1.8332880024891414
Rome 34 -1.6166266806404586
Rome 35 -1.376713856494094
Rome 36 -1.117000131013575
Rome 37 -0.8412208961462626
Rome 38 -0.5533426096958989
Rome 39 -0.25750574683774463
… … …

Two bands per sign for each city (the rows of the bands, where the curve crosses a band edge points are added):

x y band series
0.0 0.0 1 Oslo
1.0 0.47884882915567745 1 Oslo
2.0 0.9508105057085383 1 Oslo
3.0 1.4090969331003598 1 Oslo
4.0 1.8471167021659316 1 Oslo
4.371285826630546 1.9998834404599326 1 Oslo
5.0 1.9998834404599326 1 Oslo
6.0 1.9998834404599326 1 Oslo
7.0 1.9998834404599326 1 Oslo
8.0 1.9998834404599326 1 Oslo
9.0 1.9998834404599326 1 Oslo
10.0 1.9998834404599326 1 Oslo
11.0 1.9998834404599326 1 Oslo
12.0 1.9998834404599326 1 Oslo
13.0 1.9998834404599326 1 Oslo
14.0 1.9998834404599326 1 Oslo
15.0 1.9998834404599326 1 Oslo
16.0 1.9998834404599326 1 Oslo
17.0 1.9998834404599326 1 Oslo
18.0 1.9998834404599326 1 Oslo
19.0 1.9998834404599326 1 Oslo
20.0 1.9998834404599326 1 Oslo
21.0 1.9998834404599326 1 Oslo
21.811362270839258 1.9998834404599326 1 Oslo
22.0 1.9232904599545946 1 Oslo
23.0 1.4895961577002228 1 Oslo
24.0 1.0344773986444433 1 Oslo
25.0 0.5644800322394689 1 Oslo
26.0 0.08636390290438384 1 Oslo
26.18016566499168 0.0 1 Oslo
27.0 0.0 1 Oslo
28.0 0.0 1 Oslo
29.0 0.0 1 Oslo
30.0 0.0 1 Oslo
30.55150315673058 0.0 1 Oslo
31.0 0.0 1 Oslo
32.0 0.0 1 Oslo
33.0 0.0 1 Oslo
34.0 0.0 1 Oslo
35.0 0.0 1 Oslo
36.0 0.0 1 Oslo
37.0 0.0 1 Oslo
38.0 0.0 1 Oslo
39.0 0.0 1 Oslo
40.0 0.0 1 Oslo
41.0 0.0 1 Oslo
42.0 0.0 1 Oslo
43.0 0.0 1 Oslo
44.0 0.0 1 Oslo
45.0 0.0 1 Oslo
46.0 0.0 1 Oslo
47.0 0.0 1 Oslo
47.99671369528545 0.0 1 Oslo
48.0 0.0 1 Oslo
49.0 0.0 1 Oslo
50.0 0.0 1 Oslo
51.0 0.0 1 Oslo
52.0 0.0 1 Oslo
52.36003255569833 0.0 1 Oslo
53.0 0.3069566971700721 1 Oslo
54.0 0.7821860604021735 1 Oslo
55.0 1.2461654540535114 1 Oslo
56.0 1.6922215885719873 1 Oslo
56.72954512405473 1.9998834404599326 1 Oslo
57.0 1.9998834404599326 1 Oslo
58.0 1.9998834404599326 1 Oslo
59.0 1.9998834404599326 1 Oslo
0.0 0.0 2 Oslo
1.0 0.0 2 Oslo
2.0 0.0 2 Oslo
3.0 0.0 2 Oslo
4.0 0.0 2 Oslo
4.371285826630546 0.0 2 Oslo
5.0 0.2586864531202089 2 Oslo
6.0 0.6376552474259598 2 Oslo
7.0 0.9786890394235046 2 Oslo
8.0 1.2768828327440604 2 Oslo
9.0 1.5279477870798575 2 Oslo
10.0 1.7282729034089725 2 Oslo
11.0 1.8749769600131283 2 Oslo
12.0 1.9659499523068131 2 Oslo
13.0 1.9998834404599326 2 Oslo
14.0 1.9762893683323712 2 Oslo
15.0 1.8955070830528484 2 Oslo
16.0 1.758698454281367 2 Oslo
17.0 1.5678311633535857 2 Oslo
18.0 1.3256504026547997 2 Oslo
19.0 1.0356393922637555 2 Oslo
20.0 0.7019692817446712 2 Oslo
21.0 0.32943915763639486 2 Oslo
21.811362270839258 0.0 2 Oslo
22.0 0.0 2 Oslo
23.0 0.0 2 Oslo
24.0 0.0 2 Oslo
25.0 0.0 2 Oslo
26.0 0.0 2 Oslo
26.18016566499168 0.0 2 Oslo
27.0 0.0 2 Oslo
28.0 0.0 2 Oslo
29.0 0.0 2 Oslo
… … … …

The bands drawn as filled lines - default band height (left), and three bands of a fixed height 1 on a monotone curve resampled 4 points per gap (right); horizon-bands orders the colour domain:

(plot/render-image (plot/arrange [{:data (:rows (series/horizon-rows temperatures {:x :day :y :anomaly :series :city}))
                                   :mapping {:x :x :y :y :color :band :facet :series}
                                   :charts [(chart/line {:fill :color :alpha 1.0 :width 0})]
                                   :scales {:color {:kind :ordinal :domain (series/horizon-bands 2)
                                                    :range [[158 202 225] [8 69 148] [252 174 145] [165 15 21]]}}
                                   :facets {:columns 1}
                                   :labels {:title "2 bands" :y nil}
                                   :legend false}
                                  {:data (:rows (series/horizon-rows temperatures {:x :day :y :anomaly :series :city :bands 3
                                                                                   :band-height 1.0 :interpolator :monotone
                                                                                   :steps-per-gap 4}))
                                   :mapping {:x :x :y :y :color :band :facet :series}
                                   :charts [(chart/line {:fill :color :alpha 1.0 :width 0})]
                                   :scales {:color {:kind :ordinal :domain (series/horizon-bands 3)
                                                    :range [[198 219 239] [107 174 214] [8 81 156]
                                                            [252 187 161] [251 106 74] [165 15 21]]}}
                                   :facets {:columns 1}
                                   :labels {:title "3 bands of height 1, :monotone" :y nil}}]
                                 {:columns 2 :widths [1 1.2]})
                   {:width 1000 :height 360})

27.6 series/horizon-bands

The band labels of a horizon of n bands in drawing order - positive bands first, then the mirrored negative ones - the colour domain above:

(series/horizon-bands 3)
[1 2 3 -1 -2 -3]
source: notebooks/reference/data_sets_series.clj