Skip to content

Commit 73c8c1a

Browse files
remove remaining caption hacks for non-3d figs
1 parent 0b11a19 commit 73c8c1a

File tree

2 files changed

+88
-46
lines changed

2 files changed

+88
-46
lines changed

source/classification1.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ perimeter and concavity variables. Recall that the default palette in `altair`
281281
is colorblind-friendly, so we can stick with that here.
282282

283283
```{code-cell} ipython3
284+
:tags: ["remove-output"]
284285
perim_concav = alt.Chart(cancer).mark_circle().encode(
285286
x=alt.X("Perimeter").title("Perimeter (standardized)"),
286287
y=alt.Y("Concavity").title("Concavity (standardized)"),
@@ -289,12 +290,16 @@ perim_concav = alt.Chart(cancer).mark_circle().encode(
289290
perim_concav
290291
```
291292

292-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
293+
```{code-cell} ipython3
294+
:tags: ["remove-cell"]
295+
glue("fig:05-scatter", perim_concav)
296+
```
297+
298+
:::{glue:figure} fig:05-scatter
293299
:name: fig:05-scatter
294-
:figclass: caption-hack
295300

296301
Scatter plot of concavity versus perimeter colored by diagnosis label.
297-
```
302+
:::
298303

299304
+++
300305

@@ -1432,6 +1437,7 @@ The new imbalanced data is shown in {numref}`fig:05-unbalanced`,
14321437
and we print the counts of the classes using the `value_counts` function.
14331438

14341439
```{code-cell} ipython3
1440+
:tags: ["remove-output"]
14351441
rare_cancer = pd.concat((
14361442
cancer[cancer["Class"] == "Benign"],
14371443
cancer[cancer["Class"] == "Malignant"].head(3)
@@ -1445,12 +1451,16 @@ rare_plot = alt.Chart(rare_cancer).mark_circle().encode(
14451451
rare_plot
14461452
```
14471453

1448-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1454+
```{code-cell} ipython3
1455+
:tags: ["remove-cell"]
1456+
glue("fig:05-unbalanced", rare_plot)
1457+
```
1458+
1459+
:::{glue:figure} fig:05-unbalanced
14491460
:name: fig:05-unbalanced
1450-
:figclass: caption-hack
14511461

14521462
Imbalanced data.
1453-
```
1463+
:::
14541464

14551465
```{code-cell} ipython3
14561466
rare_cancer["Class"].value_counts()
@@ -1947,16 +1957,15 @@ unscaled_plot + prediction_plot
19471957
```
19481958

19491959
```{code-cell} ipython3
1950-
:tags: [remove-input]
1960+
:tags: [remove-cell]
19511961
glue("fig:05-workflow-plot", (unscaled_plot + prediction_plot))
19521962
```
19531963

1954-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1964+
:::{glue:figure} fig:05-workflow-plot
19551965
:name: fig:05-workflow-plot
1956-
:figclass: caption-hack
19571966

19581967
Scatter plot of smoothness versus area where background color indicates the decision of the classifier.
1959-
```
1968+
:::
19601969

19611970
+++
19621971

source/inference.md

Lines changed: 69 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ was \$`r round(mean(airbnb$price),2)`.
645645
-->
646646

647647
```{code-cell} ipython3
648-
:tags: [remove-input]
648+
:tags: ["remove-cell"]
649649
650650
glue(
651651
"fig:11-example-means5",
@@ -681,12 +681,12 @@ glue(
681681
)
682682
```
683683

684-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
684+
:::{glue:figure} fig:11-example-means5
685685
:name: fig:11-example-means5
686-
:figclass: caption-hack
687686

688687
Comparison of population distribution, sample distribution, and sampling distribution.
689-
```
688+
:::
689+
690690

691691
+++
692692

@@ -699,7 +699,7 @@ sampling distribution of the sample mean. We indicate the mean of the sampling
699699
distribution with a vertical line.
700700

701701
```{code-cell} ipython3
702-
:tags: [remove-input]
702+
:tags: ["remove-cell"]
703703
704704
# Plot sampling distributions for multiple sample sizes
705705
base = alt.Chart(
@@ -753,12 +753,11 @@ glue(
753753
)
754754
```
755755

756-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
756+
:::{glue:figure} fig:11-example-means7
757757
:name: fig:11-example-means7
758-
:figclass: caption-hack
759758

760759
Comparison of sampling distributions, with mean highlighted as a vertical line.
761-
```
760+
:::
762761

763762
+++
764763

@@ -963,8 +962,7 @@ one_sample
963962
```
964963

965964
```{code-cell} ipython3
966-
:tags: []
967-
965+
:tags: ["remove-output"]
968966
one_sample_dist = alt.Chart(one_sample).mark_bar().encode(
969967
x=alt.X("price")
970968
.bin(maxbins=30)
@@ -975,12 +973,17 @@ one_sample_dist = alt.Chart(one_sample).mark_bar().encode(
975973
one_sample_dist
976974
```
977975

978-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
976+
```{code-cell} ipython3
977+
:tags: ["remove-cell"]
978+
979+
glue("fig:11-bootstrapping1", one_sample_dist)
980+
```
981+
982+
:::{glue:figure} fig:11-bootstrapping1
979983
:name: fig:11-bootstrapping1
980-
:figclass: caption-hack
981984

982985
Histogram of price per night (dollars) for one sample of size 40.
983-
```
986+
:::
984987

985988
+++
986989

@@ -1002,7 +1005,7 @@ Since we need to sample with replacement when bootstrapping,
10021005
we change the `replace` parameter to `True`.
10031006

10041007
```{code-cell} ipython3
1005-
:tags: []
1008+
:tags: ["remove-output"]
10061009
10071010
boot1 = one_sample.sample(frac=1, replace=True)
10081011
boot1_dist = alt.Chart(boot1).mark_bar().encode(
@@ -1015,12 +1018,17 @@ boot1_dist = alt.Chart(boot1).mark_bar().encode(
10151018
boot1_dist
10161019
```
10171020

1018-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1021+
```{code-cell} ipython3
1022+
:tags: ["remove-cell"]
1023+
1024+
glue("fig:11-bootstrapping3", boot1_dist)
1025+
```
1026+
1027+
:::{glue:figure} fig:11-bootstrapping3
10191028
:name: fig:11-bootstrapping3
1020-
:figclass: caption-hack
10211029

10221030
Bootstrap distribution.
1023-
```
1031+
:::
10241032

10251033
```{code-cell} ipython3
10261034
boot1["price"].mean()
@@ -1055,10 +1063,10 @@ boot20000
10551063
Let's take a look at the histograms of the first six replicates of our bootstrap samples.
10561064

10571065
```{code-cell} ipython3
1058-
:tags: []
1066+
:tags: ["remove-output"]
10591067
10601068
six_bootstrap_samples = boot20000.query("replicate < 6")
1061-
alt.Chart(six_bootstrap_samples, height=150).mark_bar().encode(
1069+
six_bootstrap_fig = alt.Chart(six_bootstrap_samples, height=150).mark_bar().encode(
10621070
x=alt.X("price")
10631071
.bin(maxbins=20)
10641072
.title("Price per night (dollars)"),
@@ -1067,14 +1075,20 @@ alt.Chart(six_bootstrap_samples, height=150).mark_bar().encode(
10671075
"replicate:N", # Recall that `:N` converts the variable to a categorical type
10681076
columns=2
10691077
)
1078+
six_bootstrap_fig
10701079
```
10711080

1072-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1081+
```{code-cell} ipython3
1082+
:tags: ["remove-cell"]
1083+
1084+
glue("fig:11-bootstrapping-six-bootstrap-samples", six_bootstrap_fig)
1085+
```
1086+
1087+
:::{glue:figure} fig:11-bootstrapping-six-bootstrap-samples
10731088
:name: fig:11-bootstrapping-six-bootstrap-samples
1074-
:figclass: caption-hack
10751089

10761090
Histograms of the first six replicates of the bootstrap samples.
1077-
```
1091+
:::
10781092

10791093
+++
10801094

@@ -1125,7 +1139,7 @@ boot20000_means
11251139
```
11261140

11271141
```{code-cell} ipython3
1128-
:tags: []
1142+
:tags: ["remove-output"]
11291143
11301144
boot_est_dist = alt.Chart(boot20000_means).mark_bar().encode(
11311145
x=alt.X("mean_price")
@@ -1137,23 +1151,28 @@ boot_est_dist = alt.Chart(boot20000_means).mark_bar().encode(
11371151
boot_est_dist
11381152
```
11391153

1140-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1154+
```{code-cell} ipython3
1155+
:tags: ["remove-cell"]
1156+
1157+
glue("fig:11-bootstrapping5", boot_est_dist)
1158+
```
1159+
1160+
:::{glue:figure} fig:11-bootstrapping5
11411161
:name: fig:11-bootstrapping5
1142-
:figclass: caption-hack
11431162

11441163
Distribution of the bootstrap sample means.
1145-
```
1164+
:::
11461165

11471166
+++
11481167

11491168
Let's compare the bootstrap distribution&mdash;which we construct by taking many samples from our original sample of size 40&mdash;with
11501169
the true sampling distribution&mdash;which corresponds to taking many samples from the population.
11511170

11521171
```{code-cell} ipython3
1153-
:tags: [remove-input]
1172+
:tags: [remove-cell]
11541173
11551174
sampling_distribution.encoding.x["bin"]["extent"] = (90, 250)
1156-
alt.vconcat(
1175+
bootstr6fig = alt.vconcat(
11571176
alt.layer(
11581177
sampling_distribution,
11591178
alt.Chart(sample_estimates).mark_rule(color="black", size=1.5, strokeDash=[6]).encode(x="mean(mean_price)"),
@@ -1175,12 +1194,19 @@ alt.vconcat(
11751194
)
11761195
```
11771196

1178-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1197+
```{code-cell} ipython3
1198+
:tags: ["remove-cell"]
1199+
1200+
glue("fig:11-bootstrapping6", bootstr6fig)
1201+
```
1202+
1203+
:::{glue:figure} fig:11-bootstrapping6
11791204
:name: fig:11-bootstrapping6
1180-
:figclass: caption-hack
11811205

11821206
Comparison of the distribution of the bootstrap sample means and sampling distribution.
1183-
```
1207+
:::
1208+
1209+
11841210

11851211
```{code-cell} ipython3
11861212
:tags: [remove-cell]
@@ -1277,7 +1303,7 @@ the middle 95\% of the sample mean prices in the bootstrap distribution. We can
12771303
visualize the interval on our distribution in {numref}`fig:11-bootstrapping9`.
12781304

12791305
```{code-cell} ipython3
1280-
:tags: [remove-input]
1306+
:tags: [remove-cell]
12811307
# Create the annotation for for the 2.5th percentile
12821308
rule_025 = alt.Chart().mark_rule(color="black", size=1.5, strokeDash=[6]).encode(
12831309
x=alt.datum(ci_bounds[0.025])
@@ -1301,15 +1327,22 @@ text_975 = text_025.encode(
13011327
rule_975 = rule_025.encode(x=alt.datum(ci_bounds[0.975]))
13021328
13031329
# Layer the annotations on top of the distribution plot
1304-
boot_est_dist + rule_025 + text_025 + rule_975 + text_975
1330+
bootstr9fig = boot_est_dist + rule_025 + text_025 + rule_975 + text_975
1331+
```
1332+
1333+
```{code-cell} ipython3
1334+
:tags: ["remove-cell"]
1335+
1336+
glue("fig:11-bootstrapping9", bootstr9fig)
13051337
```
13061338

1307-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1339+
:::{glue:figure} fig:11-bootstrapping9
13081340
:name: fig:11-bootstrapping9
1309-
:figclass: caption-hack
13101341

13111342
Distribution of the bootstrap sample means with percentile lower and upper bounds.
1312-
```
1343+
:::
1344+
1345+
13131346

13141347
+++
13151348

0 commit comments

Comments
 (0)