Skip to content

Add fallback fonts & 16:9 beamer layout #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 3, 2024
Merged
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
22 changes: 13 additions & 9 deletions pub_ready_plots/pub_ready_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Generator, Union

import matplotlib.pyplot as plt
from matplotlib import rcParams
from matplotlib.axes import Axes
from matplotlib.figure import Figure
from numpy import ndarray
Expand Down Expand Up @@ -42,8 +43,8 @@ def get_mpl_rcParams(
) -> tuple[dict[str, Any], float, float]:
"""Get matplotlib rcParams dict and fig width & height in inches, depending on the
chosen layout and fractional width and height. Fractional here in the sense that
The resulting fig width/height in inches is calculated as `width_frac\\linewidth` and
`height_frac\\textheight` in LaTeX. Usage:
The resulting fig width/height in inches is calculated as `width_frac\\linewidth`
and `height_frac\\textheight` in LaTeX. Usage:

```python
rc_params, fig_width_in, fig_height_in = pub_ready_plots.get_mpl_rcParams(
Expand Down Expand Up @@ -74,11 +75,12 @@ def get_mpl_rcParams(
Args:
layout: The LaTeX template used. Possible values are Layout.ICML, Layout.NeurIPS,
Layout.ICLR, Layout.AISTATS, Layout.UAI, Layout.JMLR, Layout.TMLR,
Layout.POSTER_PORTRAIT (A1, 2-column), and Layout.POSTER_LANDSCAPE (A0, 3-col).
Layout.POSTER_PORTRAIT (A1, 2-column),
and Layout.POSTER_LANDSCAPE (A0, 3-col).
width_frac: Fraction of `\\linewidth` as the figure width. Usually set to 1.
height_frac: Fraction of `\\textheight` as the figure height. Try 0.175.
single_col: Whether the plot is single column in a layout that has multiple columns
(e.g. ICML, posters). Not supported for any other layout.
single_col: Whether the plot is single column in a layout that has multiple
columns (e.g. ICML, posters). Not supported for any other layout.

Returns:
rc_params: Matplotlib key-value rc-params. Use it via
Expand All @@ -102,7 +104,8 @@ def get_mpl_rcParams(
and single_col
):
raise ValueError(
"Double-column is only supported for ICML, AISTATS, UAI, POSTER_PORTRAIT, and POSTER_LANDSCAPE."
"""Double-column is only supported for ICML, AISTATS, UAI, """
"""POSTER_PORTRAIT, and POSTER_LANDSCAPE."""
)

format: Style = PAPER_FORMATS[layout]
Expand All @@ -111,11 +114,12 @@ def get_mpl_rcParams(
rc_params = {
"text.usetex": False,
"font.size": format.footnote_size,
"font.family": "serif",
"font.serif": format.font_name,
"font.family": "sans-serif" if is_poster else "serif",
"font.serif": [format.font_name] + rcParams["font.serif"],
"font.sans-serif": [format.font_name, "Times"] + rcParams["font.sans-serif"],
"mathtext.fontset": "stixsans" if is_poster else "cm",
"lines.linewidth": format.linewidth,
"axes.linewidth": 0.5,
"axes.linewidth": format.linewidth / 2,
"axes.titlesize": format.footnote_size,
"axes.labelsize": format.script_size,
"axes.unicode_minus": False,
Expand Down
12 changes: 12 additions & 0 deletions pub_ready_plots/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Layout(Enum):
TMLR = "tmlr"
POSTER_LANDSCAPE = "poster-landscape"
POSTER_PORTRAIT = "poster-portrait"
SLIDES_169 = "slides-169"


@dataclass
Expand Down Expand Up @@ -139,4 +140,15 @@ class Style:
tick_size=1,
tick_width=1,
),
Layout.SLIDES_169: Style(
text_width=5.5129,
col_width=5.5129,
text_height=3.48863,
font_name=FONT_NAME_AVENIR,
footnote_size=8,
script_size=7,
linewidth=1,
tick_size=1,
tick_width=0.5,
),
}