From 2eba10086983635598e751cdf1c284045b3dba4b Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Mon, 4 Nov 2019 22:31:14 -0500 Subject: [PATCH 1/2] PX templates should override, not merge into default --- packages/python/plotly/plotly/express/_core.py | 5 ++++- test/percy/plotly-express.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 3e01f445c26..286ca2ffe0d 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")) From 2fefa8fa200896f5b2d1c470d757b89baa60318a Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Tue, 5 Nov 2019 11:38:24 -0500 Subject: [PATCH 2/2] fix indent --- packages/python/plotly/plotly/express/_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 286ca2ffe0d..0337fd381a9 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1295,7 +1295,7 @@ 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: + 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 []