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

Conversation

nicolaskruchten
Copy link
Contributor

Right now, passing template={} to any px method gives strange output: it uses the pio.templates.default for most things but then uses px's internal defaults for colors. This is pretty weird and annoying, and it means that if a user wants to inline any template information, they first have to set pio.templates.default to "none", or they have to override the entire default template. Also they can't use template={}, they have to use template="none".

I think the behaviour in this PR is better, but I welcome feedback.

@@ -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)

@emmanuelle
Copy link
Contributor

Could you add a unit test which would fail with the current behaviour and pass with your PR?

@emmanuelle
Copy link
Contributor

With this modification, what would be the recommended way to create a template copying an existing one but changing a few parameters? Defining the new template in pio.templates and then passing template="plotly_dark+my_patch" to the px function? Or another way?
We could document this in https://plot.ly/python/templates/

@nicolaskruchten
Copy link
Contributor Author

Re unit-tests: this is basically what the Percy test does, although you don't get to see the "before" :)

@nicolaskruchten
Copy link
Contributor Author

Defining the new template in pio.templates and then passing template="plotly_dark+my_patch" to the px function?

Yes, basically. Right now you have to do this to overwrite, and this PR basically flips this around.

@nicolaskruchten
Copy link
Contributor Author

bundled into #1875 with tests

@nicolaskruchten nicolaskruchten deleted the px_template_overwrite branch June 19, 2020 16:13
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.

2 participants