diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 3e01f445c26..0337fd381a9 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -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} @@ -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: + fig.update_layout(template=args["template"], overwrite=True) + fig.frames = frame_list if len(frames) > 1 else [] fig._px_trendlines = pd.DataFrame(trendline_rows) diff --git a/test/percy/plotly-express.py b/test/percy/plotly-express.py index 01b9bb63386..896631d4303 100644 --- a/test/percy/plotly-express.py +++ b/test/percy/plotly-express.py @@ -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"))