Skip to content

Commit 721ca46

Browse files
authored
Enhance tueplots' documentation (#162)
* Update the mentioning of available styles * Write module-level docstrings for axes.py and __init__.py * Module-level docstrings for all modules * Add usage examples to most module-level docstrings * Demo figsizes & fontsizes together because they go together * Delete an unused sphinx extension * Remove the doctests from tox * Remove latex requirements from the doctests * Don't use tex in __init__ docstring
1 parent 5ba25ec commit 721ca46

16 files changed

+236
-15
lines changed

docs/source/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
2020
# ones.
2121
extensions = [
22+
"matplotlib.sphinxext.plot_directive",
2223
"sphinx.ext.autodoc",
2324
"sphinx.ext.viewcode",
2425
"sphinx.ext.todo",

docs/source/index.rst

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
TUEplots reference documentation
77
================================
88

9-
TUEplots is a light-weight matplotlib extension
10-
that adapts your figure sizes to formats more suitable for scientific publications.
11-
It produces configurations that are compatible with matplotlib's `rcParams`,
12-
and provides fonts, figure sizes, font sizes, color schemes, and more, for a number of publication formats.
9+
TUEplots is a light-weight matplotlib extension that adapts your figure sizes to formats more suitable for scientific publications.
10+
It produces configurations that are compatible with matplotlib's `rcParams`, and provides fonts, figure sizes, font sizes, color schemes, and more, for a number of publication formats.
1311

1412

1513
Supported Venues
@@ -23,6 +21,12 @@ The following venues are currently supported by TUEplots out of the box as pre-c
2321
- International Conference on Machine Learning (ICML)
2422
- Conference on Uncertainty in Artificial Intelligence (UAI)
2523
- Journal of Machine Learning Research (JMLR)
24+
- Transactions of Machine Learning Research (TMLR)
25+
- Conference on Computer Vision and Pattern Recognition (CVPR)
26+
- Association for the Advancement of Artificial Intelligence (AAAI)
27+
- European Conference on Computer Vision (ECCV)
28+
- International Conference on Probabilistic Numerics (ProbNum)
29+
2630

2731
For further details on the available bundles, check out the `tueplots.bundles API documentation <docs_api/tueplots.bundles.rst>`_.
2832

tox.ini

+2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ deps =
1010
pytest-cases
1111
matplotlib
1212
commands =
13+
; The doctests in the src are not run here because the doc-build executes them
1314
pytest {posargs}
1415
python -m doctest docs/source/getting_started/application_icml2022.md
1516
python -m doctest docs/source/getting_started/usage_example.md
1617

1718

19+
1820
[testenv:format-and-lint]
1921
description = Lint the code with black, isort, and pylint
2022
deps =

tueplots/__init__.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1-
"""TUEplots."""
1+
"""``tueplots`` package.
2+
3+
``tueplots`` is a Python package that helps you create plots that match the styles and guidelines of different conferences and journals.
4+
Each module in TUEplots provides specific settings like fonts, figure sizes, axes behavior, and bundled configurations for specific conferences.
5+
6+
Examples
7+
--------
8+
9+
.. plot::
10+
:include-source: True
11+
12+
>>> import matplotlib.pyplot as plt
13+
>>> from tueplots import bundles
14+
>>>
15+
>>> # Select a style bundle
16+
>>> style = bundles.icml2024(usetex=False)
17+
>>>
18+
>>> # Apply the style to matplotlib
19+
>>> plt.rcParams.update(style)
20+
>>>
21+
>>> # Create a plot
22+
>>> fig, ax = plt.subplots()
23+
>>> ax.plot([0, 1, 2], [2, 1, 3])
24+
>>> ax.set_xlabel("$x$ label")
25+
>>> ax.set_ylabel("$y$ label")
26+
>>> plt.show()
27+
"""
228

329
from ._version import version as __version__

tueplots/axes.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
1-
"""Axes behaviour."""
1+
"""Customise matplotlib axes (:mod:`tueplots.axes`).
2+
3+
Provides functions to adjust axis appearance, including grid lines,
4+
spines, ticks, and legends.
5+
6+
Examples
7+
--------
8+
9+
.. plot::
10+
:include-source: True
11+
12+
>>> import matplotlib.pyplot as plt
13+
>>> from tueplots import axes
14+
>>>
15+
>>> # Select a style bundle
16+
>>> style = axes.spines(right=False, top=False)
17+
>>>
18+
>>> # Apply the style to matplotlib
19+
>>> plt.rcParams.update(style)
20+
>>>
21+
>>> # Create a plot
22+
>>> fig, ax = plt.subplots()
23+
>>> ax.plot([0, 1, 2], [2, 1, 3])
24+
>>> ax.set_xlabel("$x$ label")
25+
>>> ax.set_ylabel("$y$ label")
26+
>>> plt.show()
27+
"""
228

329

430
def lines(

tueplots/bundles.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
"""Bundled configurations."""
1+
"""Predefined style settings (:mod:`tueplots.bundles`).
2+
3+
Includes ready-to-use style configurations for major conferences
4+
and journals. Bundles figure sizes, font sizes, fonts, and so on.
5+
6+
Examples
7+
--------
8+
9+
.. plot::
10+
:include-source: True
11+
12+
>>> import matplotlib.pyplot as plt
13+
>>> from tueplots import bundles
14+
>>>
15+
>>> # Select a style bundle
16+
>>> style = bundles.neurips2021(usetex=False)
17+
>>>
18+
>>> # Apply the style to matplotlib
19+
>>> plt.rcParams.update(style)
20+
>>>
21+
>>> # Create a plot
22+
>>> fig, ax = plt.subplots()
23+
>>> ax.plot([0, 1, 2], [2, 1, 3])
24+
>>> ax.set_xlabel("$x$ label")
25+
>>> ax.set_ylabel("$y$ label")
26+
>>> plt.show()
27+
28+
"""
229

330
from tueplots import axes, cycler, figsizes, fonts, fontsizes
431
from tueplots.constants.color import palettes, rgb

tueplots/constants/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Collection of predefined constants (:mod:`tueplots.constants`).
2+
3+
Provides standardised values for colours, line styles, markers,
4+
and figure sizes.
5+
"""

tueplots/constants/color/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Colour definitions and tools (:mod:`tueplots.constants.color`).
2+
3+
Includes named colours and utilities for working with colour schemes.
4+
"""

tueplots/constants/color/palettes.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""Color palettes."""
1+
"""Predefined colour palettes (:mod:`tueplots.constants.color.palettes`).
2+
3+
Offers curated colour sets for consistent and visually appealing plots.
4+
"""
25

36
import numpy as np
47

tueplots/constants/color/rgb.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""RGB color constants."""
1+
"""Standard colour definitions (:mod:`tueplots.constants.colours`).
2+
3+
Lists predefined colours for consistency in visualisations.
4+
"""
25

36
import numpy as np
47

tueplots/constants/markers.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""Marker collections."""
1+
"""Marker shape presets (:mod:`tueplots.constants.markers`).
2+
3+
Defines commonly used marker styles for plots.
4+
"""
25

36
import numpy as _np
47

tueplots/cycler.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
"""Wrapper for matplotlib cycler."""
1+
"""Colour and style cycling (:mod:`tueplots.cycler`).
2+
3+
Defines custom cyclers for colours, markers, and line styles to
4+
keep plots visually distinct.
5+
"""
26

37
from matplotlib import cycler as mpl_cycler
48

tueplots/figsizes.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1-
"""Figure size settings."""
1+
"""Figure size presets (:mod:`tueplots.figsizes`).
2+
3+
Provides standard figure dimensions for publications, ensuring
4+
proper scaling in papers.
5+
6+
Examples
7+
--------
8+
9+
.. plot::
10+
:include-source: True
11+
12+
>>> import matplotlib.pyplot as plt
13+
>>> from tueplots import figsizes, fontsizes
14+
>>>
15+
>>> # Select a style bundle: fontsize + figsize
16+
>>> style = figsizes.aistats2025_half() | fontsizes.aistats2025()
17+
>>>
18+
>>> # Apply the style to matplotlib
19+
>>> plt.rcParams.update(style)
20+
>>>
21+
>>> # Create a plot
22+
>>> fig, ax = plt.subplots()
23+
>>> ax.plot([0, 1, 2], [2, 1, 3])
24+
>>> ax.set_xlabel("$x$ label")
25+
>>> ax.set_ylabel("$y$ label")
26+
>>> plt.show()
27+
28+
29+
"""
230

331
# Some useful constants
432
_GOLDEN_RATIO = (5.0**0.5 - 1.0) / 2.0

tueplots/fonts.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1-
"""Font settings for conference papers and journals."""
1+
"""Font settings for plots (:mod:`tueplots.fonts`).
2+
3+
Configures fonts to match LaTeX documents.
4+
5+
6+
Examples
7+
--------
8+
9+
.. plot::
10+
:include-source: True
11+
12+
>>> import matplotlib.pyplot as plt
13+
>>> from tueplots import fonts
14+
>>>
15+
>>> # Select a style bundle
16+
>>> style = fonts.neurips2021()
17+
>>>
18+
>>> # Apply the style to matplotlib
19+
>>> plt.rcParams.update(style)
20+
>>>
21+
>>> # Create a plot
22+
>>> fig, ax = plt.subplots()
23+
>>> ax.plot([0, 1, 2], [2, 1, 3])
24+
>>> ax.set_xlabel("$x$ label")
25+
>>> ax.set_ylabel("$y$ label")
26+
>>> plt.show()
27+
28+
29+
"""
230

331

432
def neurips2021(*, family="serif"):

tueplots/fontsizes.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,33 @@
1-
"""Fontsize settings."""
1+
"""Adapt font sizes (:mod:`tueplots.fontsizes`).
2+
3+
Sets appropriate font sizes for labels, legends, and titles
4+
in publication-ready figures.
5+
6+
7+
Examples
8+
--------
9+
10+
.. plot::
11+
:include-source: True
12+
13+
>>> import matplotlib.pyplot as plt
14+
>>> from tueplots import fontsizes, figsizes
15+
>>>
16+
>>> # Select a style bundle: fontsize + figsize
17+
>>> style = fontsizes.cvpr2024() | figsizes.cvpr2022_half()
18+
>>>
19+
>>> # Apply the style to matplotlib
20+
>>> plt.rcParams.update(style)
21+
>>>
22+
>>> # Create a plot
23+
>>> fig, ax = plt.subplots()
24+
>>> ax.plot([0, 1, 2], [2, 1, 3])
25+
>>> ax.set_xlabel("$x$ label")
26+
>>> ax.set_ylabel("$y$ label")
27+
>>> plt.show()
28+
29+
30+
"""
231

332

433
def icml2022(*, default_smaller=1):

tueplots/markers.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1-
"""Marker styles."""
1+
"""Marker styles and sizes (:mod:`tueplots.markers`).
2+
3+
Provides predefined marker shapes and sizes for scatter plots
4+
and line charts.
5+
6+
Examples
7+
--------
8+
9+
.. plot::
10+
:include-source: True
11+
12+
>>> import matplotlib.pyplot as plt
13+
>>> from tueplots import markers
14+
>>>
15+
>>> # Select a style bundle
16+
>>> style = markers.with_edge()
17+
>>>
18+
>>> # Apply the style to matplotlib
19+
>>> plt.rcParams.update(style)
20+
>>>
21+
>>> # Create a plot
22+
>>> fig, ax = plt.subplots()
23+
>>> ax.plot([0, 1, 2], [2, 1, 3], "o-")
24+
>>> ax.set_xlabel("$x$ label")
25+
>>> ax.set_ylabel("$y$ label")
26+
>>> plt.show()
27+
28+
29+
"""
230

331

432
def with_edge(*, edgecolor="black", edgewidth=0.5):

0 commit comments

Comments
 (0)