From 9a6e6f034093ea4c1b4e5e48269af7649b1f0f97 Mon Sep 17 00:00:00 2001 From: KainanP Date: Wed, 2 Dec 2026 16:38:46 -0300 Subject: [PATCH 1/2] Keep title style properties in to_templated to_templated skipped every property named "title" by default. Titles have been compound objects since plotly.py 4, so this dropped the whole title from the template, including title.font, title.x and the axis title fonts. Skip only "text" by default, which keeps the title text out of the template as the docstring says, and moves the other title properties to the template. Fixes #3580 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 ++ plotly/io/_templates.py | 8 ++--- .../test_graph_objs/test_template.py | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dba830298e..72d760f5165 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Fixed +- Fix `plotly.io.to_templated` dropping title style properties such as `title.font` instead of moving them to the template; only the title text is kept out of the template now [[#3580](https://github.com/plotly/plotly.py/issues/3580)] + ## [7.2.0] - 2026-11-24 diff --git a/plotly/io/_templates.py b/plotly/io/_templates.py index 160ee7c4075..66af137862a 100644 --- a/plotly/io/_templates.py +++ b/plotly/io/_templates.py @@ -342,7 +342,7 @@ def walk_push_to_template(fig_obj, template_obj, skip): pass -def to_templated(fig, skip=("title", "text")): +def to_templated(fig, skip=("text",)): """ Return a copy of a figure where all styling properties have been moved into the figure's template. The template property of the resulting figure @@ -354,9 +354,9 @@ def to_templated(fig, skip=("title", "text")): Figure object or dict representing a figure skip A collection of names of properties to skip when moving properties to - the template. Defaults to ('title', 'text') so that the text - of figure titles, axis titles, and annotations does not become part of - the template + the template. Defaults to ('text',) so that the text of figure + titles, axis titles, and annotations does not become part of the + template, while their other properties (such as the title font) do Examples -------- diff --git a/tests/test_core/test_graph_objs/test_template.py b/tests/test_core/test_graph_objs/test_template.py index e1edd5e076a..5660d0e8c88 100644 --- a/tests/test_core/test_graph_objs/test_template.py +++ b/tests/test_core/test_graph_objs/test_template.py @@ -229,6 +229,38 @@ def test_move_layout_nested_properties_no_skip(self): ) self.assertEqual(templated_fig, expected_fig) + def test_move_layout_title_style_properties(self): + # Title style properties are moved to the template, but the title + # text is not (https://github.com/plotly/plotly.py/issues/3580) + fig = go.Figure( + layout={ + "title": { + "text": "Hello", + "font": {"family": "Times New Roman", "size": 24}, + "x": 0.5, + }, + "xaxis": {"title": {"text": "X", "font": {"color": "red"}}}, + } + ) + templated_fig = pio.to_templated(fig) + + expected_fig = go.Figure( + layout={ + "template": { + "layout": { + "title": { + "font": {"family": "Times New Roman", "size": 24}, + "x": 0.5, + }, + "xaxis": {"title": {"font": {"color": "red"}}}, + }, + }, + "title": {"text": "Hello"}, + "xaxis": {"title": {"text": "X"}}, + } + ) + self.assertEqual(templated_fig, expected_fig) + def test_move_layout_nested_with_existing_template(self): fig = go.Figure( layout={ From d59ffbafa5178290f76c8d412109fa72850d7a25 Mon Sep 17 00:00:00 2001 From: KainanP Date: Thu, 3 Dec 2026 04:55:51 -0300 Subject: [PATCH 2/2] Link the changelog entry to the pull request Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72d760f5165..18bf4f85976 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased ### Fixed -- Fix `plotly.io.to_templated` dropping title style properties such as `title.font` instead of moving them to the template; only the title text is kept out of the template now [[#3580](https://github.com/plotly/plotly.py/issues/3580)] +- Fix `plotly.io.to_templated` dropping title style properties such as `title.font` instead of moving them to the template; only the title text is kept out of the template now [[#5924](https://github.com/plotly/plotly.py/pull/5924)] ## [7.2.0] - 2026-11-24