From d0bbcc53398bc6e6e8d6d365c647ab5c9b2b5762 Mon Sep 17 00:00:00 2001 From: Peng Gao Date: Tue, 2 Nov 2021 11:54:22 +0800 Subject: [PATCH 1/2] Add recipe for installing custom fonts Signed-off-by: Peng Gao --- docs/using/recipes.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/using/recipes.md b/docs/using/recipes.md index 93845839..7759376d 100644 --- a/docs/using/recipes.md +++ b/docs/using/recipes.md @@ -549,3 +549,20 @@ RUN echo "from pyspark.sql import SparkSession" > /tmp/init-delta.py && \ python /tmp/init-delta.py && \ rm /tmp/init-delta.py ``` + +## Add Custom Font in Scipy notebook + +The example below is a Dockerfile to load Source Han Sans with normal weight which is usually used for web. + +```dockerfile +FROM jupyter/scipy-notebook:latest + +RUN PYV=$(ls $CONDA_DIR/lib | grep ^python) && \ + MPL_DATA=$CONDA_DIR/lib/$PYV/site-packages/matplotlib/mpl-data && \ + wget --quiet -P $MPL_DATA/fonts/ttf/ https://mirrors.cloud.tencent.com/adobe-fonts/source-han-sans/SubsetOTF/CN/SourceHanSansCN-Normal.otf && \ + sed -i 's/#font.family/font.family/g' $MPL_DATA/matplotlibrc && \ + sed -i 's/#font.sans-serif:/font.sans-serif: Source Han Sans CN,/g' $MPL_DATA/matplotlibrc && \ + sed -i 's/#axes.unicode_minus: True/axes.unicode_minus: False/g' $MPL_DATA/matplotlibrc && \ + rm -rf ~/.cache/matplotlib && \ + python -c 'import matplotlib.font_manager;print("font loaded: ",("Source Han Sans CN" in [f.name for f in matplotlib.font_manager.fontManager.ttflist]))' +``` From e76894fb6d6cc169c9f5ecf9a05e834ded1b6c1e Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Tue, 2 Nov 2021 12:35:57 +0300 Subject: [PATCH 2/2] Better bash syntax --- docs/using/recipes.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/using/recipes.md b/docs/using/recipes.md index 7759376d..183e6a95 100644 --- a/docs/using/recipes.md +++ b/docs/using/recipes.md @@ -557,12 +557,12 @@ The example below is a Dockerfile to load Source Han Sans with normal weight whi ```dockerfile FROM jupyter/scipy-notebook:latest -RUN PYV=$(ls $CONDA_DIR/lib | grep ^python) && \ - MPL_DATA=$CONDA_DIR/lib/$PYV/site-packages/matplotlib/mpl-data && \ - wget --quiet -P $MPL_DATA/fonts/ttf/ https://mirrors.cloud.tencent.com/adobe-fonts/source-han-sans/SubsetOTF/CN/SourceHanSansCN-Normal.otf && \ - sed -i 's/#font.family/font.family/g' $MPL_DATA/matplotlibrc && \ - sed -i 's/#font.sans-serif:/font.sans-serif: Source Han Sans CN,/g' $MPL_DATA/matplotlibrc && \ - sed -i 's/#axes.unicode_minus: True/axes.unicode_minus: False/g' $MPL_DATA/matplotlibrc && \ - rm -rf ~/.cache/matplotlib && \ +RUN PYV=$(ls "${CONDA_DIR}/lib" | grep ^python) && \ + MPL_DATA="${CONDA_DIR}/lib/${PYV}/site-packages/matplotlib/mpl-data" && \ + wget --quiet -P "${MPL_DATA}/fonts/ttf/" https://mirrors.cloud.tencent.com/adobe-fonts/source-han-sans/SubsetOTF/CN/SourceHanSansCN-Normal.otf && \ + sed -i 's/#font.family/font.family/g' "${MPL_DATA}/matplotlibrc" && \ + sed -i 's/#font.sans-serif:/font.sans-serif: Source Han Sans CN,/g' "${MPL_DATA}/matplotlibrc" && \ + sed -i 's/#axes.unicode_minus: True/axes.unicode_minus: False/g' "${MPL_DATA}/matplotlibrc" && \ + rm -rf "/home/${NB_USER}/.cache/matplotlib" && \ python -c 'import matplotlib.font_manager;print("font loaded: ",("Source Han Sans CN" in [f.name for f in matplotlib.font_manager.fontManager.ttflist]))' ```