diff --git a/CHANGELOG.md b/CHANGELOG.md index 232ccdfe2c..81628e300a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/plotly/_subplots.py b/plotly/_subplots.py index 16a3958637..55da6e96f4 100644 --- a/plotly/_subplots.py +++ b/plotly/_subplots.py @@ -58,6 +58,7 @@ def make_subplots( x_title=None, y_title=None, figure=None, + font=None, **kwargs, ): """ @@ -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 -------- @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 @@ -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" @@ -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, }