diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 6104b9d4..a35951c9 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -55,8 +55,6 @@ jobs: sudo sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml # make -C fonts/ - cp -r fonts/ /usr/share/fonts/ - fc-cache make all - name: Run checks run: | diff --git a/.gitignore b/.gitignore index 3761438c..683aae45 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ handout-*.png # ---------------------------------- figures/*.pdf fonts/**/*.[ot]tf +scripts/__pycache__/ # html build docs/_build/* diff --git a/Makefile b/Makefile index aa863ad1..ee83744a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ SRC := $(wildcard *.tex) +SCRIPTS := $(filter-out _%, $(notdir $(wildcard scripts/*.py))) CONVERTFLAGS = -density 150 -alpha remove -depth 8 .PHONY: default @@ -10,7 +11,7 @@ all: figures cheatsheets handouts docs .PHONY: figures figures: # generate the figures - cd scripts && for script in *.py; do echo $$script; MPLBACKEND="agg" python $$script; done + cd scripts && for script in $(SCRIPTS); do echo $$script; MPLBACKEND="agg" python $$script; done # crop some of the figures cd figures && pdfcrop adjustments.pdf adjustments.pdf cd figures && pdfcrop annotate.pdf annotate.pdf diff --git a/README.md b/README.md index 8894c054..7d92c83a 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Beginner handout [(download pdf)](https://matplotlib.org/cheatsheets/handout-beg ## How to compile -1. You need to create a `fonts` repository with: +1. You need to fill the `fonts` directory with: * `fonts/roboto/*` : See https://fonts.google.com/specimen/Roboto or https://github.com/googlefonts/roboto/tree/master/src/hinted @@ -34,17 +34,6 @@ On Linux, with `make` installed, the fonts can be set up with the following comm make -C fonts ``` -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)): - -```xml - - - -/path/to/cheatsheets/fonts/ -... - -``` - 2. You need to generate all the figures: diff --git a/scripts/_custom_fonts.py b/scripts/_custom_fonts.py new file mode 100644 index 00000000..f6b6832c --- /dev/null +++ b/scripts/_custom_fonts.py @@ -0,0 +1,9 @@ +from pathlib import Path + +from matplotlib.font_manager import fontManager + + +def setup(): + root_dir = Path(__file__).parent.parent.resolve() + for font in root_dir.glob('fonts/*/*.[ot]tf'): + fontManager.addfont(font) diff --git a/scripts/adjustements.py b/scripts/adjustements.py index eeb434e1..897c9a80 100644 --- a/scripts/adjustements.py +++ b/scripts/adjustements.py @@ -9,9 +9,12 @@ import matplotlib.pyplot as plt import matplotlib.patches as mpatches +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ]) diff --git a/scripts/advanced-plots.py b/scripts/advanced-plots.py index f5980878..68476fa2 100644 --- a/scripts/advanced-plots.py +++ b/scripts/advanced-plots.py @@ -10,9 +10,12 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ROOT_DIR / 'styles/plotlet.mplstyle', diff --git a/scripts/anatomy.py b/scripts/anatomy.py index a8daf883..dc29785e 100644 --- a/scripts/anatomy.py +++ b/scripts/anatomy.py @@ -10,9 +10,12 @@ import matplotlib.pyplot as plt from matplotlib.ticker import AutoMinorLocator, MultipleLocator, FuncFormatter +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ]) diff --git a/scripts/annotate.py b/scripts/annotate.py index c5d692ab..913db0f2 100644 --- a/scripts/annotate.py +++ b/scripts/annotate.py @@ -6,8 +6,11 @@ import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() fig = plt.figure(figsize=(6, 1)) # ax = plt.subplot(111, frameon=False, aspect=.1) diff --git a/scripts/annotation-arrow-styles.py b/scripts/annotation-arrow-styles.py index 26ac9503..b9487877 100644 --- a/scripts/annotation-arrow-styles.py +++ b/scripts/annotation-arrow-styles.py @@ -3,8 +3,11 @@ import matplotlib.pyplot as plt import matplotlib.patches as mpatches +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() styles = mpatches.ArrowStyle.get_styles() diff --git a/scripts/annotation-connection-styles.py b/scripts/annotation-connection-styles.py index 057b5cdc..c35101d8 100644 --- a/scripts/annotation-connection-styles.py +++ b/scripts/annotation-connection-styles.py @@ -3,9 +3,12 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ROOT_DIR / 'styles/plotlet-grid.mplstyle', diff --git a/scripts/basic-plots.py b/scripts/basic-plots.py index 8350326b..3500e9d8 100644 --- a/scripts/basic-plots.py +++ b/scripts/basic-plots.py @@ -10,9 +10,12 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ROOT_DIR / 'styles/plotlet.mplstyle', diff --git a/scripts/colorbar.py b/scripts/colorbar.py index 6ffba8fa..d6fcfb0d 100644 --- a/scripts/colorbar.py +++ b/scripts/colorbar.py @@ -9,8 +9,11 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() fig = plt.figure(figsize=(6, .65)) # ax = plt.subplot(111, frameon=False, aspect=.1) diff --git a/scripts/colormaps.py b/scripts/colormaps.py index 1ccdea84..827e97ef 100644 --- a/scripts/colormaps.py +++ b/scripts/colormaps.py @@ -3,8 +3,11 @@ import numpy as np import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() figsize = 4.0, 0.25 fig = plt.figure(figsize=figsize) diff --git a/scripts/colornames.py b/scripts/colornames.py index a0597878..75db79dc 100644 --- a/scripts/colornames.py +++ b/scripts/colornames.py @@ -10,9 +10,12 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ]) diff --git a/scripts/colors.py b/scripts/colors.py index 86e3a706..b33d926e 100644 --- a/scripts/colors.py +++ b/scripts/colors.py @@ -9,8 +9,11 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() figsize = 4.0, 0.25 fig = plt.figure(figsize=figsize) diff --git a/scripts/extents.py b/scripts/extents.py index 2eab814b..95309372 100644 --- a/scripts/extents.py +++ b/scripts/extents.py @@ -8,9 +8,12 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ]) diff --git a/scripts/fonts.py b/scripts/fonts.py index f7475a98..e79b8690 100644 --- a/scripts/fonts.py +++ b/scripts/fonts.py @@ -6,8 +6,11 @@ import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() fig = plt.figure(figsize=(4.25, 3.8)) ax = fig.add_axes([0, 0, 1, 1], frameon=False, xticks=[], yticks=[], diff --git a/scripts/interpolations.py b/scripts/interpolations.py index 3cd1308e..c3adf207 100644 --- a/scripts/interpolations.py +++ b/scripts/interpolations.py @@ -4,9 +4,12 @@ import matplotlib.pyplot as plt import numpy as np +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ROOT_DIR / 'styles/plotlet-grid.mplstyle', diff --git a/scripts/layouts.py b/scripts/layouts.py index 49f7340b..3db920b4 100644 --- a/scripts/layouts.py +++ b/scripts/layouts.py @@ -9,8 +9,11 @@ import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() fig = plt.figure(figsize=(0.4, 0.4)) margin = 0.01 diff --git a/scripts/legend.py b/scripts/legend.py index c78b6730..dd478980 100644 --- a/scripts/legend.py +++ b/scripts/legend.py @@ -7,9 +7,12 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ]) diff --git a/scripts/linestyles.py b/scripts/linestyles.py index 17736fee..0316c1b0 100644 --- a/scripts/linestyles.py +++ b/scripts/linestyles.py @@ -7,8 +7,11 @@ import numpy as np import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() fig = plt.figure(figsize=(4.25, 2*.55)) ax = fig.add_axes([0, 0, 1, 1], xlim=[0.75, 10.25], ylim=[0.5, 2.5], frameon=False, diff --git a/scripts/markers.py b/scripts/markers.py index 0b787e00..fe382a74 100644 --- a/scripts/markers.py +++ b/scripts/markers.py @@ -7,8 +7,11 @@ import numpy as np import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() # Markers # ----------------------------------------------------------------------------- diff --git a/scripts/plot-variations.py b/scripts/plot-variations.py index b07bf655..6d5dadfb 100644 --- a/scripts/plot-variations.py +++ b/scripts/plot-variations.py @@ -9,9 +9,12 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ROOT_DIR / 'styles/plotlet.mplstyle', diff --git a/scripts/projections.py b/scripts/projections.py index 1f623a93..aba74b42 100644 --- a/scripts/projections.py +++ b/scripts/projections.py @@ -9,9 +9,12 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ROOT_DIR / 'styles/plotlet.mplstyle', diff --git a/scripts/scales.py b/scripts/scales.py index 70192ca2..718b8e9f 100644 --- a/scripts/scales.py +++ b/scripts/scales.py @@ -3,8 +3,11 @@ import numpy as np import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() fig = plt.figure(figsize=(0.4, 2/3*0.4)) ax = fig.add_axes([0, 0, 1, 1], frameon=False) diff --git a/scripts/sine.py b/scripts/sine.py index 63076294..53148c76 100644 --- a/scripts/sine.py +++ b/scripts/sine.py @@ -8,9 +8,12 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ROOT_DIR / 'styles/sine-plot.mplstyle', diff --git a/scripts/styles.py b/scripts/styles.py index bbcfe16d..38863626 100644 --- a/scripts/styles.py +++ b/scripts/styles.py @@ -7,8 +7,11 @@ import numpy as np import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() for style in ['default'] + plt.style.available: with plt.style.context(style): diff --git a/scripts/text-alignments.py b/scripts/text-alignments.py index 0d653b92..3d828197 100644 --- a/scripts/text-alignments.py +++ b/scripts/text-alignments.py @@ -7,8 +7,11 @@ import numpy as np import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() dpi = 100 fig = plt.figure(figsize=(4.25, 1.5), dpi=dpi) diff --git a/scripts/tick-formatters.py b/scripts/tick-formatters.py index bcdce046..a7673d15 100644 --- a/scripts/tick-formatters.py +++ b/scripts/tick-formatters.py @@ -8,8 +8,11 @@ import matplotlib.pyplot as plt import matplotlib.ticker as ticker +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() # Setup a plot such that only the bottom spine is shown diff --git a/scripts/tick-locators.py b/scripts/tick-locators.py index 4c0985ca..e8f39996 100644 --- a/scripts/tick-locators.py +++ b/scripts/tick-locators.py @@ -9,8 +9,11 @@ import matplotlib.pyplot as plt import matplotlib.ticker as ticker +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() # Setup a plot such that only the bottom spine is shown diff --git a/scripts/tick-multiple-locator.py b/scripts/tick-multiple-locator.py index 30324001..fa52dc15 100644 --- a/scripts/tick-multiple-locator.py +++ b/scripts/tick-multiple-locator.py @@ -9,9 +9,12 @@ import matplotlib.pyplot as plt import matplotlib.ticker as ticker +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.style.use([ ROOT_DIR / 'styles/base.mplstyle', ROOT_DIR / 'styles/ticks.mplstyle', diff --git a/scripts/tip-color-range.py b/scripts/tip-color-range.py index 5743940d..8b5b6e46 100644 --- a/scripts/tip-color-range.py +++ b/scripts/tip-color-range.py @@ -10,8 +10,11 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() fig = plt.figure(figsize=(2, 2)) mpl.rcParams['axes.linewidth'] = 1.5 diff --git a/scripts/tip-colorbar.py b/scripts/tip-colorbar.py index 941eb81b..87c1154d 100644 --- a/scripts/tip-colorbar.py +++ b/scripts/tip-colorbar.py @@ -10,8 +10,11 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() fig = plt.figure(figsize=(2.15, 2)) mpl.rcParams['axes.linewidth'] = 1.5 diff --git a/scripts/tip-dotted.py b/scripts/tip-dotted.py index 16f1e5cd..5c02e6e1 100644 --- a/scripts/tip-dotted.py +++ b/scripts/tip-dotted.py @@ -8,8 +8,11 @@ import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() fig = plt.figure(figsize=(5, .25)) diff --git a/scripts/tip-dual-axis.py b/scripts/tip-dual-axis.py index 9d72f344..834e9625 100644 --- a/scripts/tip-dual-axis.py +++ b/scripts/tip-dual-axis.py @@ -4,9 +4,12 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.rcParams['axes.linewidth'] = 1.5 fig = plt.figure(figsize=(2, 2)) diff --git a/scripts/tip-font-family.py b/scripts/tip-font-family.py index ab3543ac..a8bfdd6c 100644 --- a/scripts/tip-font-family.py +++ b/scripts/tip-font-family.py @@ -8,8 +8,11 @@ import matplotlib.pyplot as plt import matplotlib.ticker as ticker +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() # Setup a plot such that only the bottom spine is shown diff --git a/scripts/tip-hatched.py b/scripts/tip-hatched.py index f1a38d4c..7d0c4f92 100644 --- a/scripts/tip-hatched.py +++ b/scripts/tip-hatched.py @@ -3,8 +3,11 @@ import numpy as np import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() cmap = plt.get_cmap("Oranges") color1, color2 = cmap(0.3), cmap(0.5) diff --git a/scripts/tip-multiline.py b/scripts/tip-multiline.py index 99d704c8..6c4e277c 100644 --- a/scripts/tip-multiline.py +++ b/scripts/tip-multiline.py @@ -8,9 +8,12 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.rcParams['axes.linewidth'] = 1.5 fig = plt.figure(figsize=(8, 1.5)) diff --git a/scripts/tip-outline.py b/scripts/tip-outline.py index 6fe1a6f3..441e0b4d 100644 --- a/scripts/tip-outline.py +++ b/scripts/tip-outline.py @@ -11,8 +11,11 @@ import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() fig = plt.figure(figsize=(2, 2)) mpl.rcParams['axes.linewidth'] = 1.5 diff --git a/scripts/tip-post-processing.py b/scripts/tip-post-processing.py index 3280efe3..d0351479 100644 --- a/scripts/tip-post-processing.py +++ b/scripts/tip-post-processing.py @@ -6,8 +6,11 @@ from matplotlib.backends.backend_agg import FigureCanvas from scipy.ndimage import gaussian_filter +import _custom_fonts + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() # First pass for drop-shadow fig = Figure(figsize=(6, 1.5)) diff --git a/scripts/tip-transparency.py b/scripts/tip-transparency.py index 320ea0c4..caaf41ea 100644 --- a/scripts/tip-transparency.py +++ b/scripts/tip-transparency.py @@ -8,7 +8,11 @@ import matplotlib as mpl import matplotlib.pyplot as plt +import _custom_fonts + + ROOT_DIR = pathlib.Path(__file__).parent.parent +_custom_fonts.setup() mpl.rc('axes', linewidth=1.5)