Skip to content

Keep title style properties in to_templated - #5924

Open
KainanP wants to merge 2 commits into
plotly:mainfrom
KainanP:to-templated-title-style
Open

KainanP wants to merge 2 commits into
plotly:mainfrom
KainanP:to-templated-title-style

Conversation

@KainanP

@KainanP KainanP commented Dec 3, 2026

Copy link
Copy Markdown

Link to issue

Closes #3580

Description of change

pio.to_templated skipped every property named title by default. Titles have been objects since plotly.py 4, so the whole title was dropped, including title.font and axis title fonts. The default skip is now ("text",): the title text stays on the figure, and the other title properties go to the template.

Demo

fig = go.Figure(layout=dict(title_font=dict(family="Times New Roman", size=24)))
pio.to_templated(fig).layout.template.layout.title
# before: layout.Title({'x': 0.05})
# after:  layout.Title({'font': {'family': 'Times New Roman', 'size': 24}, 'x': 0.05})

Testing strategy

New test test_move_layout_title_style_properties in tests/test_core/test_graph_objs/test_template.py fails before the change and passes after. tests/test_core, tests/test_plotly_utils and the to_templated doctest pass; ruff check and ruff format --check are clean on the changed files.

Additional information (optional)

A caller who passes skip=("title", "text") explicitly keeps the old behaviour.

Guidelines

AI disclosure: written with Claude Code (Claude Opus 5.5), which found the cause, wrote the change and the test, and ran the checks.

🤖 Generated with Claude Code

KainanP and others added 2 commits December 3, 2026 04:33
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 plotly#3580

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@atishay-kasliwal atishay-kasliwal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran to_templated on a figure with styled titles everywhere: layout title (with x and a subtitle), x-axis title, legend title, a colorbar title and a pie trace title. Each now keeps only its text on the figure (and the subtitle's text); font, x, standoff, side and position move to the template. Main kept all of it on the figure, and the template only had defaults. Passing skip=("title", "text") gives exactly the old output. The new test fails on main, and all 34 in test_template.py pass here.

Unrelated to this change, and the same on main: per-annotation positions also go into annotationdefaults. Two annotations at (1, 1) and (2, 3) come out as text only, with a default of x=2, y=3, so both render at (2, 3).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

title_font broken within template layouts

2 participants