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

### 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 [[#5924](https://github.com/plotly/plotly.py/pull/5924)]


## [7.2.0] - 2026-11-24

Expand Down
8 changes: 4 additions & 4 deletions plotly/io/_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
--------
Expand Down
32 changes: 32 additions & 0 deletions tests/test_core/test_graph_objs/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down