A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://plotly.com/python-api-reference/generated/plotly.io.to_templated.html below:

plotly.io.to_templated — 6.3.0 documentation

Return a copy of a figure where all styling properties have been moved into the figure’s template. The template property of the resulting figure may then be used to set the default styling of other figures.

Parameters

Examples

Imports

>>> import plotly.graph_objects as go
>>> import plotly.io as pio

Construct a figure with large courier text

>>> fig = go.Figure(layout={'title': 'Figure Title',
...                         'font': {'size': 20, 'family': 'Courier'},
...                         'template':"none"})
>>> fig 
Figure({
    'data': [],
    'layout': {'font': {'family': 'Courier', 'size': 20},
               'template': '...', 'title': {'text': 'Figure Title'}}
})

Convert to a figure with a template. Note how the ‘font’ properties have been moved into the template property.

>>> templated_fig = pio.to_templated(fig)
>>> templated_fig.layout.template
layout.Template({
    'layout': {'font': {'family': 'Courier', 'size': 20}}
})
>>> templated_fig
Figure({
    'data': [], 'layout': {'template': '...', 'title': {'text': 'Figure Title'}}
})

Next create a new figure with this template

>>> fig2 = go.Figure(layout={
...     'title': 'Figure 2 Title',
...     'template': templated_fig.layout.template})
>>> fig2.layout.template
layout.Template({
    'layout': {'font': {'family': 'Courier', 'size': 20}}
})

The default font in fig2 will now be size 20 Courier.

Next, register as a named template…

>>> pio.templates['large_courier'] = templated_fig.layout.template

and specify this template by name when constructing a figure.

>>> go.Figure(layout={
...     'title': 'Figure 3 Title',
...     'template': 'large_courier'}) 
Figure(...)

Finally, set this as the default template to be applied to all new figures

>>> pio.templates.default = 'large_courier'
>>> fig = go.Figure(layout={'title': 'Figure 4 Title'})
>>> fig.layout.template
layout.Template({
    'layout': {'font': {'family': 'Courier', 'size': 20}}
})
Returns
Return type

go.Figure


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4