Skip to content

Commit db4bb3a

Browse files
committed
Add custom fonts directly to Matplotlib
This removes the need to manually install them system- or user-wide.
1 parent 05d47a5 commit db4bb3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+158
-18
lines changed

.github/workflows/main.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ jobs:
4848
sudo sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
4949
#
5050
make -C fonts/
51-
cp -r fonts/ /usr/share/fonts/
52-
fc-cache
5351
make all
5452
- name: Run checks
5553
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ handout-*.png
1616
# ----------------------------------
1717
figures/*.pdf
1818
fonts/**/*.[ot]tf
19+
fonts/__pycache__/
1920

2021
# html build
2122
docs/_build/*

README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Beginner handout [(download pdf)](https://matplotlib.org/cheatsheets/handout-beg
1515

1616
## How to compile
1717

18-
1. You need to create a `fonts` repository with:
18+
1. You need to fill the `fonts` directory with:
1919

2020
* `fonts/roboto/*` : See https://fonts.google.com/specimen/Roboto
2121
or https://github.com/googlefonts/roboto/tree/master/src/hinted
@@ -35,17 +35,6 @@ On Linux, with `make` installed, the fonts can be set up with the following comm
3535
make -C fonts
3636
```
3737

38-
The fonts can be made discoverable by `matplotlib` (through `fontconfig`) by creating the following in `$HOME/.config/fontconfig/fonts.conf` (see [here](https://www.freedesktop.org/software/fontconfig/fontconfig-user.html)):
39-
40-
```xml
41-
<?xml version="1.0"?>
42-
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
43-
<fontconfig>
44-
<dir>/path/to/cheatsheets/fonts/</dir>
45-
...
46-
</fontconfig>
47-
```
48-
4938

5039
2. You need to generate all the figures:
5140

fonts/custom_fonts.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from pathlib import Path
2+
3+
from matplotlib.font_manager import fontManager
4+
5+
6+
HERE = Path(__file__).parent.resolve()
7+
for font in HERE.glob('*/*.[ot]tf'):
8+
fontManager.addfont(font)

scripts/adjustements.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Matplotlib cheat sheet
33
# Released under the BSD License
44
# -----------------------------------------------------------------------------
5+
import sys
56
import pathlib
67

78
import numpy as np
@@ -12,6 +13,9 @@
1213

1314

1415
ROOT_DIR = pathlib.Path(__file__).parent.parent
16+
sys.path.append(str(ROOT_DIR / "fonts"))
17+
import custom_fonts # noqa
18+
1519

1620
mpl.style.use([
1721
ROOT_DIR / 'styles/base.mplstyle',

scripts/advanced-plots.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# -----------------------------------------------------------------------------
55

66
# Script to generate all the advanced plots
7+
import sys
78
import pathlib
89

910
import numpy as np
@@ -12,6 +13,9 @@
1213

1314

1415
ROOT_DIR = pathlib.Path(__file__).parent.parent
16+
sys.path.append(str(ROOT_DIR / "fonts"))
17+
import custom_fonts # noqa
18+
1519

1620
mpl.style.use([
1721
ROOT_DIR / 'styles/base.mplstyle',

scripts/anatomy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Author: Nicolas P. Rougier
44
# License: BSD
55
# ----------------------------------------------------------------------------
6+
import sys
67
import pathlib
78

89
import numpy as np
@@ -12,6 +13,9 @@
1213

1314

1415
ROOT_DIR = pathlib.Path(__file__).parent.parent
16+
sys.path.append(str(ROOT_DIR / "fonts"))
17+
import custom_fonts # noqa
18+
1519

1620
mpl.style.use([
1721
ROOT_DIR / 'styles/base.mplstyle',

scripts/annotate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Matplotlib cheat sheet
33
# Released under the BSD License
44
# -----------------------------------------------------------------------------
5+
import sys
56
import pathlib
67

78
import numpy as np
@@ -10,6 +11,9 @@
1011

1112

1213
ROOT_DIR = pathlib.Path(__file__).parent.parent
14+
sys.path.append(str(ROOT_DIR / "fonts"))
15+
import custom_fonts # noqa
16+
1317

1418
fig = plt.figure(figsize=(6, 1))
1519
# ax = plt.subplot(111, frameon=False, aspect=.1)

scripts/annotation-arrow-styles.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import sys
12
import pathlib
23

34
import matplotlib.pyplot as plt
45
import matplotlib.patches as mpatches
56

67

78
ROOT_DIR = pathlib.Path(__file__).parent.parent
9+
sys.path.append(str(ROOT_DIR / "fonts"))
10+
import custom_fonts # noqa
11+
812

913
styles = mpatches.ArrowStyle.get_styles()
1014

scripts/annotation-connection-styles.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import sys
12
import pathlib
23

34
import matplotlib as mpl
45
import matplotlib.pyplot as plt
56

67

78
ROOT_DIR = pathlib.Path(__file__).parent.parent
9+
sys.path.append(str(ROOT_DIR / "fonts"))
10+
import custom_fonts # noqa
11+
812

913
mpl.style.use([
1014
ROOT_DIR / 'styles/base.mplstyle',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy