Skip to content

Improving integration of Plotly.js templates (themes) #1161

Closed
@jonmmease

Description

@jonmmease

Some notes on integrating the new template (theme) support from plotly/plotly.js#2761 (original discussion from #924). With just rerunning code generation, in plotly.py 3.1+ template support is already usable. For example:

fig = go.FigureWidget()
fig.layout.template = {
    'layout': {'paper_bgcolor': 'lightgray'},
    'data': {'scatter': [{'mode': 'markers',
                          'marker': {'size': 20, 'symbol': 'square'}},
                         {'mode': 'markers',
                          'marker': {'size': 20, 'symbol': 'triangle'}},
                        ]}}
fig.add_scatter(y=[3, 1, 3])
fig.add_scatter(y=[1, 3, 2])
fig

newplot

Here are some of my thoughts for improving the integration for plotly.py users:

  • Write a custom validator for layout.template (right now it accepts anything and Plotly.js just ignores invalid properties)
  • Include some way to set a global template that is the default unless if it overridden in the constructor. Support saving this default to a ~/.plotly settings file.
  • Include a set of predefined named templates (like @sglyon did in WIP: adding themes #924).
  • Figure out what's going on with the new name and templateitemname properties that were added to all of the object array properties (e.g. annotations, images, etc.). I think the name properties should only show up in the template hierarchy and templateitemname should only show up in the normal object hiererahcy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions