Skip to content

Commit

Permalink
Merge pull request #84 from marvinpfoertner/rel_width
Browse files Browse the repository at this point in the history
Add `rel_width` argument for figsizes
  • Loading branch information
pnkraemer committed Feb 10, 2022
2 parents efc5924 + 4e0d005 commit 88eb7f8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 27 deletions.
14 changes: 9 additions & 5 deletions tueplots/bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,30 @@ def aistats2022(*, column="half", nrows=1, ncols=1, family="sans-serif"):
return {**font_config, **size, **fontsize_config}


def jmlr2001(*, nrows=1, ncols=1, family="sans-serif"):
def jmlr2001(*, rel_width=1.0, nrows=1, ncols=1, family="sans-serif"):
"""JMLR 2001 bundle."""
size = figsizes.jmlr2001(nrows=nrows, ncols=ncols)
size = figsizes.jmlr2001(rel_width=rel_width, nrows=nrows, ncols=ncols)
font_config = fonts.jmlr2001_tex(family=family)
fontsize_config = fontsizes.jmlr2001()
return {**font_config, **size, **fontsize_config}


def neurips2021(*, usetex=True, nrows=1, ncols=1, family="sans-serif"):
def neurips2021(*, usetex=True, rel_width=1.0, nrows=1, ncols=1, family="sans-serif"):
"""Neurips 2021 bundle."""
if usetex is True:
font_config = fonts.neurips2021_tex(family=family)
elif usetex is False:
font_config = fonts.neurips2021(family=family)
size = figsizes.neurips2021(nrows=nrows, ncols=ncols)
size = figsizes.neurips2021(rel_width=rel_width, nrows=nrows, ncols=ncols)
fontsize_config = fontsizes.neurips2021()
return {**font_config, **size, **fontsize_config}


def beamer_moml(*, rel_width=1.0, rel_height=0.8):
def beamer_moml(
*,
rel_width=1.0,
rel_height=0.8,
):
"""Beamer bundle that matches the template of the method-of-machine-learning group in Tübingen."""
size = figsizes.beamer_169(rel_width=rel_width, rel_height=rel_height)
font_config = fonts.beamer_moml()
Expand Down
64 changes: 42 additions & 22 deletions tueplots/figsizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ def _icml2022_and_aistats2022_half(
height_to_width_ratio=_GOLDEN_RATIO,
):
figsize = _from_base_in(
width_in=3.25,
base_width_in=3.25,
rel_width=1.0,
height_to_width_ratio=height_to_width_ratio,
nrows=nrows,
ncols=ncols,
height_to_width_ratio=height_to_width_ratio,
)
return _figsize_to_output_dict(
figsize=figsize,
Expand All @@ -50,17 +51,19 @@ def _icml2022_and_aistats2022_half(

def _icml2022_and_aistats2022_full(
*,
rel_width=1.0,
nrows=1,
ncols=2,
constrained_layout=True,
tight_layout=False,
height_to_width_ratio=_GOLDEN_RATIO,
):
figsize = _from_base_in(
width_in=6.75,
base_width_in=6.75,
rel_width=rel_width,
height_to_width_ratio=height_to_width_ratio,
nrows=nrows,
ncols=ncols,
height_to_width_ratio=height_to_width_ratio,
)
return _figsize_to_output_dict(
figsize=figsize,
Expand All @@ -80,10 +83,11 @@ def cvpr2022_half(
"""Double-column (half-width) figures for CVPR 2022."""

figsize = _from_base_pt(
width_pt=237.13594,
base_width_pt=237.13594,
rel_width=1.0,
height_to_width_ratio=height_to_width_ratio,
nrows=nrows,
ncols=ncols,
height_to_width_ratio=height_to_width_ratio,
)
return _figsize_to_output_dict(
figsize=figsize,
Expand All @@ -94,6 +98,7 @@ def cvpr2022_half(

def cvpr2022_full(
*,
rel_width=1.0,
nrows=1,
ncols=2,
constrained_layout=True,
Expand All @@ -103,10 +108,11 @@ def cvpr2022_full(
"""Single-column (full-width) figures for CVPR 2022."""

figsize = _from_base_pt(
width_pt=496.85625,
base_width_pt=496.85625,
rel_width=rel_width,
height_to_width_ratio=height_to_width_ratio,
nrows=nrows,
ncols=ncols,
height_to_width_ratio=height_to_width_ratio,
)
return _figsize_to_output_dict(
figsize=figsize,
Expand All @@ -120,6 +126,7 @@ def cvpr2022_full(

def jmlr2001(
*,
rel_width=1.0,
nrows=1,
ncols=2,
constrained_layout=True,
Expand All @@ -134,10 +141,11 @@ def jmlr2001(
"""

figsize = _from_base_in(
width_in=6.0,
base_width_in=6.0,
rel_width=rel_width,
height_to_width_ratio=height_to_width_ratio,
nrows=nrows,
ncols=ncols,
height_to_width_ratio=height_to_width_ratio,
)
return _figsize_to_output_dict(
figsize=figsize,
Expand All @@ -148,6 +156,7 @@ def jmlr2001(

def neurips2021(
*,
rel_width=1.0,
nrows=1,
ncols=2,
constrained_layout=True,
Expand All @@ -157,10 +166,11 @@ def neurips2021(
"""Neurips 2021 figure size."""

figsize = _from_base_pt(
width_pt=397.48499,
base_width_pt=397.48499,
rel_width=rel_width,
height_to_width_ratio=height_to_width_ratio,
nrows=nrows,
ncols=ncols,
height_to_width_ratio=height_to_width_ratio,
)
return _figsize_to_output_dict(
figsize=figsize,
Expand All @@ -169,28 +179,38 @@ def neurips2021(
)


def _from_base_pt(*, width_pt, **kwargs):
width_in = width_pt / _POINTS_PER_INCH
return _from_base_in(width_in=width_in, **kwargs)
def _from_base_pt(*, base_width_pt, **kwargs):
base_width_in = base_width_pt / _POINTS_PER_INCH
return _from_base_in(base_width_in=base_width_in, **kwargs)


def _from_base_in(*, width_in, nrows, height_to_width_ratio, ncols):
height_in = height_to_width_ratio * width_in * nrows / ncols
def _from_base_in(*, base_width_in, rel_width, height_to_width_ratio, nrows, ncols):
width_in = base_width_in * rel_width
subplot_width_in = width_in / ncols
subplot_height_in = height_to_width_ratio * subplot_width_in
height_in = subplot_height_in * nrows
return width_in, height_in


# Other formats


def beamer_169(
*, rel_width=0.9, rel_height=0.6, constrained_layout=True, tight_layout=False
*,
rel_width=0.9,
rel_height=0.6,
constrained_layout=True,
tight_layout=False,
):
"""Beamer figure size for `aspectratio=169`."""
textwidth_169_pt = 398.3386 # via '\showthe\textwidth' in latex
textwidth_169_in = textwidth_169_pt / _POINTS_PER_INCH
textheight_169_in = textwidth_169_in / 16.0 * 9.0
figsize = _from_base_pt(
base_width_pt=398.3386, # via '\showthe\textwidth' in latex
rel_width=rel_width,
height_to_width_ratio=(9 / 16) * (rel_height / rel_width),
nrows=1,
ncols=1,
)

figsize = (textwidth_169_in * rel_width, textheight_169_in * rel_height)
return _figsize_to_output_dict(
figsize=figsize,
constrained_layout=constrained_layout,
Expand Down

0 comments on commit 88eb7f8

Please sign in to comment.