Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Plotly · Function

pio.templates

plotly.io.templates stores registered Plotly themes and exposes the global default. Inspect it, select a named template for a figure, register custom templates, or change the default used by new figures.

How it works

pio.templates is Plotly's template configuration object. Inspect it to see registered themes, select a template by name for a figure, register custom templates with dictionary-style assignment, or change the default applied when a figure does not specify one.

Syntax

import plotly.io as pio
pio.templates
pio.templates.default = "plotly_white"
pio.templates["custom_name"] = template

Key points

  • Plotly supplies built-in themes, including plotly, plotly_white, plotly_dark, simple_white, and none.
  • Displaying pio.templates reveals the current default and registered template names.
  • The initial global default template is plotly.
  • Custom templates are added by assigning them to a name in the configuration object.
  • Template definitions use plotly.graph_objects.layout.Template instances.

Common mistakes

  • A figure without an explicit theme uses the current global default.
  • For graph-object figures, apply a per-figure template through layout.template.
  • Changing the default affects subsequently created figures that do not override it.

Example: Set a global default template

import plotly.io as pio
import plotly.express as px

pio.templates.default = "plotly_white"
fig = px.scatter(x=[1, 2, 3], y=[2, 1, 4], title="Styled scatter")
fig.show()

Sets the global default template before creating a Plotly Express figure.

When to use it

Global chart defaults

Set a consistent visual style across charts created in an application.

Per-figure styling

Apply a different theme to one figure without changing global configuration.

Custom theme registration

Package reusable colors, fonts, and layout conventions for a team.

Interview questions

QWhat is pio.templates used for?

pio.templates is the configuration object for registered Plotly themes. It exposes available templates and supports changing the default through its default property.

Follow-up: How would you inspect the available choices? Evaluate pio.templates or iterate over it with list(pio.templates), which returns registered names.

QHow do you change the default template?

Set pio.templates.default to a registered template name, such as "plotly_white". New Plotly Express or graph-object figures without an explicit theme then use that default.

Follow-up: How can one disable theming globally? Set pio.templates.default = "none".

QHow do you register a custom template?

A template can be registered by assigning a template object to a name in pio.templates, for example pio.templates["draft"] = custom_template. That name can then be used as a figure template or as the default.

Follow-up: What can a figure's template value be besides a registered name? It can also be a Template object or a dictionary accepted by the constructor.

  • plotly.io.templates.default
  • plotly.graph_objects.layout.Template
  • plotly.graph_objects.layout.template
  • plotly.express.defaults

Source: Theming and templates in Python - Plotly. Checked 2026-10-15.