diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 821c6ef..d2f18c1 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -48,8 +48,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/README.md b/README.md index a9d07d5..ead6d18 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 @@ -35,17 +35,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/fonts/custom_fonts.py b/fonts/custom_fonts.py new file mode 100644 index 0000000..3cba97b --- /dev/null +++ b/fonts/custom_fonts.py @@ -0,0 +1,8 @@ +from pathlib import Path + +from matplotlib.font_manager import fontManager + + +HERE = Path(__file__).parent.resolve() +for font in HERE.glob('*/*.[ot]tf'): + fontManager.addfont(font) diff --git a/scripts/adjustements.py b/scripts/adjustements.py index f1508df..7defb23 100644 --- a/scripts/adjustements.py +++ b/scripts/adjustements.py @@ -3,6 +3,7 @@ # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -12,6 +13,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + fig = plt.figure(figsize=(4.25, 4.25 * 95/115)) ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1, diff --git a/scripts/advanced-plots.py b/scripts/advanced-plots.py index 05f1bd7..450519d 100644 --- a/scripts/advanced-plots.py +++ b/scripts/advanced-plots.py @@ -4,6 +4,7 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import sys from pathlib import Path import numpy as np @@ -12,6 +13,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + fig = plt.figure(figsize=(0.4, 0.4)) mpl.rcParams['axes.linewidth'] = 0.5 diff --git a/scripts/anatomy.py b/scripts/anatomy.py index 30337c0..109a142 100644 --- a/scripts/anatomy.py +++ b/scripts/anatomy.py @@ -4,6 +4,7 @@ # License: BSD # ---------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -12,6 +13,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + np.random.seed(123) diff --git a/scripts/annotate.py b/scripts/annotate.py index 875d408..d53714e 100644 --- a/scripts/annotate.py +++ b/scripts/annotate.py @@ -2,6 +2,7 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -10,6 +11,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + 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 873be9d..1354bee 100644 --- a/scripts/annotation-arrow-styles.py +++ b/scripts/annotation-arrow-styles.py @@ -1,3 +1,4 @@ +import sys from pathlib import Path import matplotlib.pyplot as plt @@ -5,6 +6,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + styles = mpatches.ArrowStyle.get_styles() diff --git a/scripts/annotation-connection-styles.py b/scripts/annotation-connection-styles.py index 83bb11c..e97b546 100644 --- a/scripts/annotation-connection-styles.py +++ b/scripts/annotation-connection-styles.py @@ -1,9 +1,12 @@ +import sys from pathlib import Path import matplotlib.pyplot as plt REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa def demo_con_style(ax, connectionstyle): diff --git a/scripts/basic-plots.py b/scripts/basic-plots.py index f51b92d..97ad764 100644 --- a/scripts/basic-plots.py +++ b/scripts/basic-plots.py @@ -4,6 +4,7 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import sys from pathlib import Path import numpy as np @@ -12,6 +13,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + fig = plt.figure(figsize=(0.4, 0.4)) mpl.rcParams['axes.linewidth'] = 0.5 diff --git a/scripts/colorbar.py b/scripts/colorbar.py index 078554d..6cd7561 100644 --- a/scripts/colorbar.py +++ b/scripts/colorbar.py @@ -3,6 +3,7 @@ # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -11,6 +12,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + 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 d663134..f365286 100644 --- a/scripts/colormaps.py +++ b/scripts/colormaps.py @@ -1,3 +1,4 @@ +import sys from pathlib import Path import numpy as np @@ -5,6 +6,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + figsize = 4.0, 0.25 fig = plt.figure(figsize=figsize) diff --git a/scripts/colornames.py b/scripts/colornames.py index 6481ae7..54d9674 100644 --- a/scripts/colornames.py +++ b/scripts/colornames.py @@ -6,6 +6,7 @@ Simple plot example with the named colors and its visual representation. """ +import sys from pathlib import Path import matplotlib.pyplot as plt @@ -13,6 +14,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS) diff --git a/scripts/colors.py b/scripts/colors.py index 758f3a3..898ef11 100644 --- a/scripts/colors.py +++ b/scripts/colors.py @@ -3,6 +3,7 @@ # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -11,6 +12,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + figsize = 4.0, 0.25 fig = plt.figure(figsize=figsize) diff --git a/scripts/extents.py b/scripts/extents.py index 277e168..b2e7208 100644 --- a/scripts/extents.py +++ b/scripts/extents.py @@ -3,6 +3,7 @@ # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path # Scripts to generate all the basic plots @@ -12,6 +13,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + Z = np.arange(5*5).reshape(5, 5) diff --git a/scripts/fonts.py b/scripts/fonts.py index 6698772..da50b5d 100644 --- a/scripts/fonts.py +++ b/scripts/fonts.py @@ -2,12 +2,16 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import matplotlib.pyplot as plt REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + fig = plt.figure(figsize=(4.25, 3.8)) ax = fig.add_axes([0, 0, 1, 1], frameon=False, xticks=[], yticks=[], @@ -17,13 +21,13 @@ # ----------------------------------------------------------------------------- variants = { - "normal" : "../fonts/eb-garamond/EBGaramond08-Regular.otf", - "small-caps" : "../fonts/eb-garamond/EBGaramondSC08-Regular.otf" + "normal" : "EB Garamond", + "small-caps" : "EB Garamond SC" } text = "The quick brown fox jumps over the lazy dog" -for i, (variant, file) in enumerate(variants.items()): - ax.text(1, y, text, size=9, va="center", font=Path(file).resolve()) +for i, (variant, family) in enumerate(variants.items()): + ax.text(1, y, text, size=9, va="center", family=family) ax.text(39, y, variant, color="0.25", va="center", ha="right", diff --git a/scripts/interpolations.py b/scripts/interpolations.py index b6122d3..3b74919 100644 --- a/scripts/interpolations.py +++ b/scripts/interpolations.py @@ -1,3 +1,4 @@ +import sys from pathlib import Path import matplotlib.pyplot as plt @@ -5,6 +6,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + methods = [None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', diff --git a/scripts/layouts.py b/scripts/layouts.py index 613369e..eb7f51f 100644 --- a/scripts/layouts.py +++ b/scripts/layouts.py @@ -2,6 +2,7 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -11,6 +12,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + fig = plt.figure(figsize=(0.4, 0.4)) margin = 0.01 diff --git a/scripts/legend.py b/scripts/legend.py index ee2729e..693a60b 100644 --- a/scripts/legend.py +++ b/scripts/legend.py @@ -2,6 +2,7 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -10,6 +11,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + fig = plt.figure(figsize=(4, 4)) ax = fig.add_axes([0.15, 0.15, .7, .7], frameon=True, aspect=1, diff --git a/scripts/linestyles.py b/scripts/linestyles.py index aceaba9..c8ca1d2 100644 --- a/scripts/linestyles.py +++ b/scripts/linestyles.py @@ -2,6 +2,7 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -9,6 +10,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + 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 085e05d..a622a69 100644 --- a/scripts/markers.py +++ b/scripts/markers.py @@ -2,6 +2,7 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -9,6 +10,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + # Markers # ----------------------------------------------------------------------------- diff --git a/scripts/plot-variations.py b/scripts/plot-variations.py index 0380482..8c36d26 100644 --- a/scripts/plot-variations.py +++ b/scripts/plot-variations.py @@ -4,6 +4,7 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import sys from pathlib import Path import numpy as np @@ -12,6 +13,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + fig = plt.figure(figsize=(0.4, 0.4)) mpl.rcParams['axes.linewidth'] = 0.5 diff --git a/scripts/projections.py b/scripts/projections.py index fe2bdce..b9643b6 100644 --- a/scripts/projections.py +++ b/scripts/projections.py @@ -2,6 +2,7 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -11,6 +12,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + CARTOPY_SOURCE_TEMPLATE = 'https://naturalearth.s3.amazonaws.com/{resolution}_{category}/ne_{resolution}_{name}.zip' diff --git a/scripts/scales.py b/scripts/scales.py index 9c6d6d8..545a519 100644 --- a/scripts/scales.py +++ b/scripts/scales.py @@ -1,3 +1,4 @@ +import sys from pathlib import Path import numpy as np @@ -5,6 +6,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + 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 455b2dc..b6c82b2 100644 --- a/scripts/sine.py +++ b/scripts/sine.py @@ -2,6 +2,7 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -9,6 +10,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + X = np.linspace(0.1, 10*np.pi, 10000) Y = np.sin(X) diff --git a/scripts/styles.py b/scripts/styles.py index 6c070d6..7f49311 100644 --- a/scripts/styles.py +++ b/scripts/styles.py @@ -2,6 +2,7 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -10,6 +11,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + 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 f9f7bc8..f8d1753 100644 --- a/scripts/text-alignments.py +++ b/scripts/text-alignments.py @@ -2,6 +2,7 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -9,6 +10,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + 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 41df9d7..f320bc2 100644 --- a/scripts/tick-formatters.py +++ b/scripts/tick-formatters.py @@ -3,6 +3,7 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import sys from pathlib import Path import matplotlib.pyplot as plt @@ -10,6 +11,8 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa # Setup a plot such that only the bottom spine is shown diff --git a/scripts/tick-locators.py b/scripts/tick-locators.py index 4d7acd0..cd615d7 100644 --- a/scripts/tick-locators.py +++ b/scripts/tick-locators.py @@ -3,6 +3,7 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -11,6 +12,8 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa # 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 e19bfe7..511ee3f 100644 --- a/scripts/tick-multiple-locator.py +++ b/scripts/tick-multiple-locator.py @@ -3,6 +3,7 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -11,6 +12,8 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa # Setup a plot such that only the bottom spine is shown @@ -41,8 +44,6 @@ def setup(ax): # Null Locator ax = plt.subplot(n, 1, 1) -# ax.tick_params(axis='both', which='major', -# labelsize=10, family="Roboto Condensed") ax.tick_params(axis='both', which='minor', labelsize=6) setup(ax) diff --git a/scripts/tip-color-range.py b/scripts/tip-color-range.py index ce47a98..e0a941f 100644 --- a/scripts/tip-color-range.py +++ b/scripts/tip-color-range.py @@ -4,6 +4,7 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import sys from pathlib import Path import numpy as np @@ -12,6 +13,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + 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 bfc56ba..75a84e8 100644 --- a/scripts/tip-colorbar.py +++ b/scripts/tip-colorbar.py @@ -4,6 +4,7 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import sys from pathlib import Path import numpy as np @@ -13,6 +14,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + 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 db46edf..efd229b 100644 --- a/scripts/tip-dotted.py +++ b/scripts/tip-dotted.py @@ -4,6 +4,7 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import sys from pathlib import Path import numpy as np @@ -12,6 +13,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + fig = plt.figure(figsize=(5, .25)) diff --git a/scripts/tip-dual-axis.py b/scripts/tip-dual-axis.py index 78735e5..3f20c67 100644 --- a/scripts/tip-dual-axis.py +++ b/scripts/tip-dual-axis.py @@ -1,3 +1,4 @@ +import sys from pathlib import Path import numpy as np @@ -6,6 +7,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + mpl.rcParams['axes.linewidth'] = 1.5 diff --git a/scripts/tip-font-family.py b/scripts/tip-font-family.py index 77b9f5b..15c3017 100644 --- a/scripts/tip-font-family.py +++ b/scripts/tip-font-family.py @@ -3,6 +3,7 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -11,6 +12,8 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa # Setup a plot such that only the bottom spine is shown diff --git a/scripts/tip-hatched.py b/scripts/tip-hatched.py index d6add6c..4edba4e 100644 --- a/scripts/tip-hatched.py +++ b/scripts/tip-hatched.py @@ -1,3 +1,4 @@ +import sys from pathlib import Path import numpy as np @@ -5,6 +6,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + 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 3b3e622..b0c2cdc 100644 --- a/scripts/tip-multiline.py +++ b/scripts/tip-multiline.py @@ -2,6 +2,7 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -10,6 +11,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + mpl.rcParams['axes.linewidth'] = 1.5 diff --git a/scripts/tip-outline.py b/scripts/tip-outline.py index ca3fdea..7dab68e 100644 --- a/scripts/tip-outline.py +++ b/scripts/tip-outline.py @@ -4,6 +4,7 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import sys from pathlib import Path import numpy as np @@ -13,6 +14,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + 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 7897a23..1a7e3b3 100644 --- a/scripts/tip-post-processing.py +++ b/scripts/tip-post-processing.py @@ -1,3 +1,4 @@ +import sys from pathlib import Path import numpy as np @@ -8,6 +9,9 @@ REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + # First pass for drop-shadow fig = Figure(figsize=(6, 1.5)) diff --git a/scripts/tip-transparency.py b/scripts/tip-transparency.py index b897bf4..5cb1a70 100644 --- a/scripts/tip-transparency.py +++ b/scripts/tip-transparency.py @@ -2,6 +2,7 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import sys from pathlib import Path import numpy as np @@ -9,6 +10,9 @@ import matplotlib.pyplot as plt REPO = Path(__file__).parent.parent +sys.path.append(str(REPO / "fonts")) +import custom_fonts # noqa + mpl.rc('axes', linewidth=1.5)