Skip to content

PX templates should override, not merge into default #1871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
cmax=range_color[1],
colorbar=dict(title=get_decorated_label(args, args[colorvar], colorvar)),
)
for v in ["title", "height", "width", "template"]:
for v in ["title", "height", "width"]:
if args[v]:
layout_patch[v] = args[v]
layout_patch["legend"] = {"tracegroupgap": 0}
Expand Down Expand Up @@ -1295,6 +1295,9 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
# Add traces, layout and frames to figure
fig.add_traces(frame_list[0]["data"] if len(frame_list) > 0 else [])
fig.layout.update(layout_patch)
if "template" in args and args["template"] is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

unexpected indent here (makes the CI fail)

fig.update_layout(template=args["template"], overwrite=True)

fig.frames = frame_list if len(frames) > 1 else []

fig._px_trendlines = pd.DataFrame(trendline_rows)
Expand Down
10 changes: 10 additions & 0 deletions test/percy/plotly-express.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,13 @@
range_color=[20, 80],
)
fig.write_html(os.path.join(dir_name, "choropleth.html"), auto_play=False)

### test template overriding (should be white background, courier font)

import plotly.express as px

iris = px.data.iris()
fig = px.scatter(
iris, x="sepal_width", y="sepal_length", template=dict(layout_font_family="Courier")
)
fig.write_html(os.path.join(dir_name, "scatter.html"))