Skip to content

Commit c400462

Browse files
authored
Merge pull request #1508 from ggaaooppeenngg/custom-font-recipe
Add recipe for installing custom fonts
2 parents ae640b0 + e76894f commit c400462

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/using/recipes.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,20 @@ RUN echo "from pyspark.sql import SparkSession" > /tmp/init-delta.py && \
549549
python /tmp/init-delta.py && \
550550
rm /tmp/init-delta.py
551551
```
552+
553+
## Add Custom Font in Scipy notebook
554+
555+
The example below is a Dockerfile to load Source Han Sans with normal weight which is usually used for web.
556+
557+
```dockerfile
558+
FROM jupyter/scipy-notebook:latest
559+
560+
RUN PYV=$(ls "${CONDA_DIR}/lib" | grep ^python) && \
561+
MPL_DATA="${CONDA_DIR}/lib/${PYV}/site-packages/matplotlib/mpl-data" && \
562+
wget --quiet -P "${MPL_DATA}/fonts/ttf/" https://mirrors.cloud.tencent.com/adobe-fonts/source-han-sans/SubsetOTF/CN/SourceHanSansCN-Normal.otf && \
563+
sed -i 's/#font.family/font.family/g' "${MPL_DATA}/matplotlibrc" && \
564+
sed -i 's/#font.sans-serif:/font.sans-serif: Source Han Sans CN,/g' "${MPL_DATA}/matplotlibrc" && \
565+
sed -i 's/#axes.unicode_minus: True/axes.unicode_minus: False/g' "${MPL_DATA}/matplotlibrc" && \
566+
rm -rf "/home/${NB_USER}/.cache/matplotlib" && \
567+
python -c 'import matplotlib.font_manager;print("font loaded: ",("Source Han Sans CN" in [f.name for f in matplotlib.font_manager.fontManager.ttflist]))'
568+
```

0 commit comments

Comments
 (0)