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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Added
- Add optional `font` parameter for `make_subplots` [[#5393](https://github.com/plotly/plotly.py/pull/5393)]

## [6.4.0] - 2025-11-02

### Updated
Expand Down
22 changes: 15 additions & 7 deletions plotly/_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def make_subplots(
x_title=None,
y_title=None,
figure=None,
font=None,
**kwargs,
):
"""
Expand Down Expand Up @@ -235,6 +236,9 @@ def make_subplots(
layout of this figure and this figure will be returned. If the figure
already contains axes, they will be overwritten.

font: dict (default None)
Font used by any title of the subplots.

Examples
--------

Expand Down Expand Up @@ -814,7 +818,7 @@ def _check_hv_spacing(dimsize, spacing, name, dimvarname, dimname):

# Add subplot titles
plot_title_annotations = _build_subplot_title_annotations(
subplot_titles, list_of_domains
subplot_titles, list_of_domains, font=font
)

layout["annotations"] = plot_title_annotations
Expand All @@ -835,7 +839,7 @@ def _check_hv_spacing(dimsize, spacing, name, dimvarname, dimname):

# Add subplot titles
column_title_annotations = _build_subplot_title_annotations(
column_titles, domains_list
column_titles, domains_list, font=font
)

layout["annotations"] += tuple(column_title_annotations)
Expand All @@ -849,7 +853,7 @@ def _check_hv_spacing(dimsize, spacing, name, dimvarname, dimname):

# Add subplot titles
column_title_annotations = _build_subplot_title_annotations(
row_titles, domains_list, title_edge="right"
row_titles, domains_list, title_edge="right", font=font
)

layout["annotations"] += tuple(column_title_annotations)
Expand All @@ -859,7 +863,7 @@ def _check_hv_spacing(dimsize, spacing, name, dimvarname, dimname):

# Add subplot titles
column_title_annotations = _build_subplot_title_annotations(
[x_title], domains_list, title_edge="bottom", offset=30
[x_title], domains_list, title_edge="bottom", offset=30, font=font
)

layout["annotations"] += tuple(column_title_annotations)
Expand All @@ -869,7 +873,7 @@ def _check_hv_spacing(dimsize, spacing, name, dimvarname, dimname):

# Add subplot titles
column_title_annotations = _build_subplot_title_annotations(
[y_title], domains_list, title_edge="left", offset=40
[y_title], domains_list, title_edge="left", offset=40, font=font
)

layout["annotations"] += tuple(column_title_annotations)
Expand Down Expand Up @@ -1163,7 +1167,7 @@ def _get_cartesian_label(x_or_y, r, c, cnt):


def _build_subplot_title_annotations(
subplot_titles, list_of_domains, title_edge="top", offset=0
subplot_titles, list_of_domains, title_edge="top", offset=0, font=None
):
# If shared_axes is False (default) use list_of_domains
# This is used for insets and irregular layouts
Expand All @@ -1173,6 +1177,10 @@ def _build_subplot_title_annotations(
subtitle_pos_x = []
subtitle_pos_y = []

# If no font size is provided, use this fallback
if font is None:
font = dict(size=16)

if title_edge == "top":
text_angle = 0
xanchor = "center"
Expand Down Expand Up @@ -1236,7 +1244,7 @@ def _build_subplot_title_annotations(
"yref": "paper",
"text": subplot_titles[index],
"showarrow": False,
"font": dict(size=16),
"font": font,
"xanchor": xanchor,
"yanchor": yanchor,
}
Expand Down