Skip to content

Commit 744c8f3

Browse files
pdf vs html build 3d images
1 parent 73d4301 commit 744c8f3

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

source/classification1.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ kernelspec:
1616
:tags: [remove-cell]
1717
from chapter_preamble import *
1818
from IPython.display import HTML
19+
from IPython.display import Image
1920
from sklearn.metrics.pairwise import euclidean_distances
2021
import numpy as np
2122
import plotly.express as px
@@ -860,7 +861,11 @@ for neighbor_df in neighbor_df_list:
860861
# tight layout
861862
fig.update_layout(margin=dict(l=0, r=0, b=0, t=1), template="plotly_white")
862863
863-
glue("fig:05-more", fig)
864+
# if HTML, use the plotly 3d image; if PDF, use static image
865+
if "BOOK_BUILD_TYPE" in os.environ and os.environ["BOOK_BUILD_TYPE"] == "PDF":
866+
glue("fig:05-more", Image("img/classification1/plot3d_knn_classification.png"))
867+
else:
868+
glue("fig:05-more", fig)
864869
```
865870

866871
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7

source/regression1.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ kernelspec:
2020
2121
from chapter_preamble import *
2222
from IPython.display import HTML
23+
from IPython.display import Image
2324
import plotly.express as px
2425
import plotly.graph_objects as go
2526
```
@@ -1148,7 +1149,11 @@ fig.update_layout(
11481149
template="plotly_white",
11491150
)
11501151
1151-
glue("fig:07-knn-mult-viz", fig)
1152+
# if HTML, use the plotly 3d image; if PDF, use static image
1153+
if "BOOK_BUILD_TYPE" in os.environ and os.environ["BOOK_BUILD_TYPE"] == "PDF":
1154+
glue("fig:07-knn-mult-viz", Image("img/regression1/plot3d_knn_regression.png"))
1155+
else:
1156+
glue("fig:07-knn-mult-viz", fig)
11521157
```
11531158

11541159
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7

source/regression2.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ kernelspec:
2020
2121
from chapter_preamble import *
2222
from IPython.display import HTML
23+
from IPython.display import Image
2324
import numpy as np
2425
import plotly.express as px
2526
import plotly.graph_objects as go
@@ -827,7 +828,11 @@ fig.update_layout(
827828
template="plotly_white",
828829
)
829830
830-
glue("fig:08-3DlinReg", fig)
831+
# if HTML, use the plotly 3d image; if PDF, use static image
832+
if "BOOK_BUILD_TYPE" in os.environ and os.environ["BOOK_BUILD_TYPE"] == "PDF":
833+
glue("fig:08-3DlinReg", Image("img/regression2/plot3d_linear_regression.png"))
834+
else:
835+
glue("fig:08-3DlinReg", fig)
831836
```
832837

833838
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7

0 commit comments

Comments
 (0)