Skip to content

Commit f2c6cca

Browse files
authored
Update style defaults: figure sizes, font sizes, and padding (#90)
* fix: Update figure sizes * chore: Update dependencies * fix: Update font sizes * fix: Update comment * chore: Re-execute notebooks * fix: Fix type errors * refactor: Rename "float_wide" to "float" * fix: Change "float_wide" to "float" * fix: Update `FIGURE_SIZES_IN_INCHES` * fix: Fix font rendering on Plotly figures * chore: Execute all notebooks
1 parent 23db239 commit f2c6cca

16 files changed

+743
-770
lines changed

arcadia_pycolor/mpl.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ def save_figure(
173173
filepath (str): Path to save the figure to.
174174
size (FigureSize): The size of the figure, which must be one of the following:
175175
- "full_wide"
176-
- "full_square"
177-
- "float_wide"
178-
- "float_square"
176+
- "float"
179177
- "half_square"
180178
filetypes (list[str], optional): The file types(s) to save the figure to.
181179
If None, the original filetype of `filepath` is used.
@@ -507,9 +505,7 @@ def get_figure_dimensions(size: FigureSize) -> tuple[float, float]:
507505
Args:
508506
size (FigureSize): The size of the figure, which must be one of the following:
509507
- "full_wide"
510-
- "full_square"
511-
- "float_wide"
512-
- "float_square"
508+
- "float"
513509
- "half_square"
514510
515511
Returns:

arcadia_pycolor/plotly_utils.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ def save_figure(
151151
filepath (str): The path to save the figure to.
152152
size (FigureSize): The size of the figure, which must be one of the following:
153153
- "full_wide"
154-
- "full_square"
155-
- "float_wide"
156-
- "float_square"
154+
- "float"
157155
- "half_square"
158156
filetypes (list[str], optional): The file types(s) to save the figure to.
159157
If None, the original filetype of `filepath` is used.
@@ -168,8 +166,8 @@ def save_figure(
168166
# so that the correct margins can be applied in Adobe Illustrator.
169167
# TODO(#69): Write a custom function to apply the margins.
170168
updated_margins = dict(l=0, r=0, t=0, b=0)
171-
updated_width = FIGURE_SIZES_IN_PIXELS[size][0] - 80
172-
updated_height = FIGURE_SIZES_IN_PIXELS[size][1] - 80
169+
updated_width = FIGURE_SIZES_IN_PIXELS[size][0] - 60
170+
updated_height = FIGURE_SIZES_IN_PIXELS[size][1] - 60
173171

174172
# For some reason, the axis linewidths (which are set to 1 px) are being rendered as
175173
# 1 pt in Illustrator. Manually setting these to 0.75 px renders them as 0.75 pt.
@@ -927,9 +925,7 @@ def set_figure_dimensions(fig: go.Figure, size: FigureSize) -> None:
927925
fig (go.Figure): The figure to modify.
928926
size (FigureSize): The size of the figure, which must be one of the following:
929927
- "full_wide"
930-
- "full_square"
931-
- "float_wide"
932-
- "float_square"
928+
- "float"
933929
- "half_square"
934930
935931
Raises:

arcadia_pycolor/style_defaults.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,45 @@
1212
BASE_DPI = 72
1313
PRINT_DPI = 300
1414

15-
FIGURE_PADDING_PIXELS = 20
15+
FIGURE_PADDING_PIXELS = 30
1616
FIGURE_PADDING_INCHES = FIGURE_PADDING_PIXELS / BASE_DPI
1717

1818
# Common figure sizes for Arcadia Creative Cloud library templates.
19-
FigureSize = Literal["full_wide", "full_square", "float_wide", "float_square", "half_square"]
19+
FigureSize = Literal["full_wide", "float", "half_square"]
2020

21-
# This dictionary contains figure sizes in inches WITHOUT padding for the transparent border.
22-
# For example, the "full_wide" figure width is 13.33333333 inches, or 960 pixels at 72 DPI.
21+
# This dictionary contains figure sizes in inches WITH padding for the transparent border.
22+
# For example, the "full_wide" figure width is 13.8888888889 inches, or 1000 pixels at 72 DPI.
2323
# They are used to set dimensions for matplotlib figures.
2424
FIGURE_SIZES_IN_INCHES: dict[FigureSize, tuple[float, float]] = {
25-
"full_wide": (13.33333333, 5.27777777),
26-
"full_square": (6.52777777, 6.52777777),
27-
"float_wide": (9.16666667, 5.27777777),
28-
"float_square": (4.44444444, 4.44444444),
29-
"half_square": (6.38888888, 6.38888888),
25+
"full_wide": (13.8888888889, 5.27777777),
26+
"float": (9.02777777778, 5.27777777),
27+
"half_square": (6.80555555556, 6.80555555556),
3028
}
3129

3230
# This dictionary contains full figure sizes in pixels WITH padding for the transparent border.
33-
# For example, the "full_wide" figure width is 960 pixels plus 20 pixels of padding on each side.
31+
# For example, the "full_wide" figure width is 940 pixels plus 30 pixels of padding on each side.
3432
# They are used to set dimensions for Plotly figures.
3533
FIGURE_SIZES_IN_PIXELS: dict[FigureSize, tuple[int, int]] = {
3634
"full_wide": (1000, 420),
37-
"full_square": (500, 500),
38-
"float_wide": (700, 420),
39-
"float_square": (360, 360),
40-
"half_square": (500, 500),
35+
"float": (650, 420),
36+
"half_square": (490, 490),
4137
}
4238

4339
# Font families.
4440
FONT_FILTER = "Atkinson"
4541
DEFAULT_FONT = "Atkinson Hyperlegible Next"
4642
MONOSPACE_FONT = "Atkinson Hyperlegible Mono"
4743

48-
DEFAULT_FONT_PLOTLY = "AtkinsonHyperlegibleNext"
49-
MONOSPACE_FONT_PLOTLY = "AtkinsonHyperlegibleMono"
44+
DEFAULT_FONT_PLOTLY = f"AtkinsonHyperlegibleNext, {DEFAULT_FONT}"
45+
DEFAULT_FONT_PLOTLY_MEDIUM = f"AtkinsonHyperlegibleNext-Medium, {DEFAULT_FONT}"
46+
DEFAULT_FONT_PLOTLY_SEMIBOLD = f"AtkinsonHyperlegibleNext-SemiBold, {DEFAULT_FONT}"
47+
MONOSPACE_FONT_PLOTLY = f"AtkinsonHyperlegibleMono, {MONOSPACE_FONT}"
5048

5149
# Font sizes.
52-
BASE_FONT_SIZE = 15
53-
TITLE_FONT_SIZE = 16
54-
MONOSPACE_FONT_SIZE = 14.5
50+
TITLE_FONT_SIZE = 17 # Key title, legend title
51+
AXIS_TITLE_FONT_SIZE = 15
52+
BASE_FONT_SIZE = 15 # Axis label, key label, explanatory text
53+
MONOSPACE_FONT_SIZE = 14.5 # Numbers
5554

5655
# Specifications for categorical axes.
5756
CATEGORICAL_AXIS_TICKLENGTH = 0
@@ -89,7 +88,7 @@
8988
"axes.grid.axis": "both",
9089
"axes.grid.which": "major",
9190
"axes.prop_cycle": plt.cycler(color=palettes.all_ordered.colors), # type: ignore
92-
"axes.titlesize": TITLE_FONT_SIZE + 2,
91+
"axes.titlesize": AXIS_TITLE_FONT_SIZE,
9392
"axes.titleweight": "medium",
9493
"axes.titlepad": 16,
9594
"axes.labelsize": BASE_FONT_SIZE,
@@ -189,7 +188,7 @@
189188
ticks="outside",
190189
tickwidth=1,
191190
title=dict(
192-
font=dict(family=f"{DEFAULT_FONT_PLOTLY}-Medium", size=BASE_FONT_SIZE, color="black"),
191+
font=dict(family=DEFAULT_FONT_PLOTLY_MEDIUM, size=BASE_FONT_SIZE, color="black"),
193192
),
194193
)
195194

@@ -202,7 +201,7 @@
202201
ticks="outside",
203202
tickfont=dict(family=MONOSPACE_FONT_PLOTLY, size=MONOSPACE_FONT_SIZE),
204203
title=dict(
205-
font=dict(family=f"{DEFAULT_FONT_PLOTLY}-Medium", size=BASE_FONT_SIZE),
204+
font=dict(family=DEFAULT_FONT_PLOTLY_MEDIUM, size=BASE_FONT_SIZE),
206205
side="right",
207206
),
208207
),
@@ -219,7 +218,7 @@
219218
),
220219
legend=go.layout.Legend(
221220
title=dict(
222-
font=dict(family=f"{DEFAULT_FONT_PLOTLY}-SemiBold", size=TITLE_FONT_SIZE, color="black")
221+
font=dict(family=DEFAULT_FONT_PLOTLY_SEMIBOLD, size=TITLE_FONT_SIZE, color="black")
223222
),
224223
font=dict(family=DEFAULT_FONT_PLOTLY, size=BASE_FONT_SIZE, color="black"),
225224
indentation=-12,
@@ -240,7 +239,7 @@
240239
zaxis=go.layout.scene.ZAxis(**PLOTLY_3D_AXIS_ATTRIBUTES),
241240
),
242241
title=go.layout.Title(
243-
font=dict(family=f"{DEFAULT_FONT_PLOTLY}-SemiBold", size=TITLE_FONT_SIZE, color="black"),
242+
font=dict(family=DEFAULT_FONT_PLOTLY_SEMIBOLD, size=TITLE_FONT_SIZE, color="black"),
244243
automargin=True,
245244
yref="container",
246245
),
@@ -254,7 +253,7 @@
254253
ticks="outside",
255254
tickwidth=1,
256255
title=dict(
257-
font=dict(family=f"{DEFAULT_FONT_PLOTLY}-Medium", size=BASE_FONT_SIZE, color="black"),
256+
font=dict(family=DEFAULT_FONT_PLOTLY_MEDIUM, size=BASE_FONT_SIZE, color="black"),
258257
standoff=10,
259258
),
260259
zerolinecolor="rgba(0,0,0,0)",
@@ -270,7 +269,7 @@
270269
ticks="outside",
271270
tickwidth=1,
272271
title=dict(
273-
font=dict(family=f"{DEFAULT_FONT_PLOTLY}-Medium", size=BASE_FONT_SIZE, color="black"),
272+
font=dict(family=DEFAULT_FONT_PLOTLY_MEDIUM, size=BASE_FONT_SIZE, color="black"),
274273
standoff=10,
275274
),
276275
zerolinecolor="rgba(0,0,0,0)",

arcadia_pycolor/tests/test_plotly_save_figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def simple_plot():
1313
labels={"x": "Proteins", "y": "Molecular Weight (kDa)"},
1414
)
1515
apc.plotly.style_plot(fig, categorical_axes="x", monospaced_axes="y")
16-
apc.plotly.set_figure_dimensions(fig, "full_square")
16+
apc.plotly.set_figure_dimensions(fig, "half_square")
1717
return fig
1818

1919

@@ -36,7 +36,7 @@ def test_plotly_save_figure_filetype_examples(tmp_path, fname, filetypes, expect
3636
apc.plotly.save_figure(
3737
fig,
3838
tmp_path / fname,
39-
"full_square",
39+
"half_square",
4040
filetypes=filetypes,
4141
)
4242
for output in expected_outputs:
@@ -58,7 +58,7 @@ def test_plotly_save_figure_filetype_invalid(tmp_path, fname, filetypes, capsys)
5858
apc.plotly.save_figure(
5959
fig,
6060
tmp_path / fname,
61-
"float_square",
61+
"float",
6262
filetypes=filetypes,
6363
)
6464
captured = capsys.readouterr()

docs/color_usage.ipynb

Lines changed: 116 additions & 116 deletions
Large diffs are not rendered by default.

docs/color_vision_deficiency_tools.ipynb

Lines changed: 33 additions & 33 deletions
Large diffs are not rendered by default.

docs/examples/3d_plots.ipynb

Lines changed: 58 additions & 58 deletions
Large diffs are not rendered by default.

docs/examples/bar_plots.ipynb

Lines changed: 126 additions & 126 deletions
Large diffs are not rendered by default.

docs/examples/heatmaps.ipynb

Lines changed: 44 additions & 44 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)