Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ handout-*.png
# ----------------------------------
figures/*.pdf
fonts/**/*.[ot]tf
scripts/__pycache__/

# html build
docs/_build/*
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SRC := $(wildcard *.tex)
SCRIPTS := $(filter-out _%, $(notdir $(wildcard scripts/*.py)))
CONVERTFLAGS = -density 150 -alpha remove -depth 8

.PHONY: default
Expand All @@ -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
Expand Down
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/path/to/cheatsheets/fonts/</dir>
...
</fontconfig>
```


2. You need to generate all the figures:

Expand Down
9 changes: 9 additions & 0 deletions scripts/_custom_fonts.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To convey that this file does something on import, could it be renamed to setup_fonts.py?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, put the code in a function and then in all the files below have something like

import custom_fonts
custom_fonts.setup_fonts()

It's a bit more verbose, but more obvious that code is being run to setup the fonts. I'm not too bothered either way, just a suggestion.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done.

Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions scripts/adjustements.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
import matplotlib.patches as mpatches
from matplotlib.collections import PatchCollection

import _custom_fonts


ROOT_DIR = pathlib.Path(__file__).parent.parent

_custom_fonts.setup()
mpl.style.use([
ROOT_DIR / 'styles/base.mplstyle',
])
Expand Down
3 changes: 3 additions & 0 deletions scripts/advanced-plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions scripts/anatomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
Expand Down
3 changes: 3 additions & 0 deletions scripts/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,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, 1))
# ax = plt.subplot(111, frameon=False, aspect=.1)
Expand Down
3 changes: 3 additions & 0 deletions scripts/annotation-arrow-styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 3 additions & 0 deletions scripts/annotation-connection-styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions scripts/basic-plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions scripts/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions scripts/colormaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions scripts/colornames.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
Expand Down
3 changes: 3 additions & 0 deletions scripts/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions scripts/extents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
Expand Down
3 changes: 3 additions & 0 deletions scripts/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[],
Expand Down
3 changes: 3 additions & 0 deletions scripts/interpolations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions scripts/layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions scripts/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
Expand Down
3 changes: 3 additions & 0 deletions scripts/linestyles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions scripts/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# -----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions scripts/plot-variations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions scripts/projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions scripts/scales.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions scripts/sine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions scripts/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import matplotlib as mpl
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):
Expand Down
3 changes: 3 additions & 0 deletions scripts/text-alignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions scripts/tick-formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions scripts/tick-locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading