MCPcopy Index your code
hub / github.com/plotly/plotly.py / to_templated

Function to_templated

plotly/io/_templates.py:345–492  ·  view source on GitHub ↗

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 ---------- fig Figure object or dict representi

(fig, skip=("title", "text"))

Source from the content-addressed store, hash-verified

343
344
345def to_templated(fig, skip=("title", "text")):
346 """
347 Return a copy of a figure where all styling properties have been moved
348 into the figure's template. The template property of the resulting figure
349 may then be used to set the default styling of other figures.
350
351 Parameters
352 ----------
353 fig
354 Figure object or dict representing a figure
355 skip
356 A collection of names of properties to skip when moving properties to
357 the template. Defaults to ('title', 'text') so that the text
358 of figure titles, axis titles, and annotations does not become part of
359 the template
360
361 Examples
362 --------
363 Imports
364
365 >>> import plotly.graph_objs as go
366 >>> import plotly.io as pio
367
368 Construct a figure with large courier text
369
370 >>> fig = go.Figure(layout={'title': 'Figure Title',
371 ... 'font': {'size': 20, 'family': 'Courier'},
372 ... 'template':"none"})
373 >>> fig # doctest: +NORMALIZE_WHITESPACE
374 Figure({
375 'data': [],
376 'layout': {'font': {'family': 'Courier', 'size': 20},
377 'template': '...', 'title': {'text': 'Figure Title'}}
378 })
379
380 Convert to a figure with a template. Note how the 'font' properties have
381 been moved into the template property.
382
383 >>> templated_fig = pio.to_templated(fig)
384 >>> templated_fig.layout.template
385 layout.Template({
386 'layout': {'font': {'family': 'Courier', 'size': 20}}
387 })
388 >>> templated_fig
389 Figure({
390 'data': [], 'layout': {'template': '...', 'title': {'text': 'Figure Title'}}
391 })
392
393
394 Next create a new figure with this template
395
396 >>> fig2 = go.Figure(layout={
397 ... 'title': 'Figure 2 Title',
398 ... 'template': templated_fig.layout.template})
399 >>> fig2.layout.template
400 layout.Template({
401 'layout': {'font': {'family': 'Courier', 'size': 20}}
402 })

Callers

nothing calls this directly

Calls 5

FigureClass · 0.90
walk_push_to_templateFunction · 0.85
addMethod · 0.45
getMethod · 0.45
to_plotly_jsonMethod · 0.45

Tested by

no test coverage detected