Setting the Font, Title, Legend Entries, and Axis Titles in Python

How to set the global font, title, legend-entries, and axis-titles in python.

New to Plotly?

Plotly is a free and open-source graphing library for Python. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.

In [1]:
import plotly.graph_objects as go

fig = go.Figure()

    x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
    y=[0, 1, 2, 3, 4, 5, 6, 7, 8],
    name="Name of Trace 1"       # this sets its legend entry

    x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
    y=[1, 0, 3, 2, 5, 4, 7, 6, 8],
    name="Name of Trace 2"

    title="Plot Title",
    xaxis_title="x Axis Title",
    yaxis_title="y Axis Title",
        family="Courier New, monospace",

The configuration of the legend is discussed in detail in the Legends page.

Align Plot Title

The following example shows how to align the plot title in layout.title. x sets the x position with respect to xref from "0" (left) to "1" (right), and y sets the y position with respect to yref from "0" (bottom) to "1" (top). Moreover, you can define xanchor to left,right, or center for setting the title's horizontal alignment with respect to its x position, and/or yanchor to top, bottom, or middle for setting the title's vertical alignment with respect to its y position.

In [2]:
import plotly.graph_objects as go

fig = go.Figure(go.Scatter(
    y=[3, 1, 4],
    x=["Mon", "Tue", "Wed"]))

        'text': "Plot Title",
        'xanchor': 'center',
        'yanchor': 'top'})


See for more information!

What About Dash?

Dash is an open-source framework for building analytical applications, with no Javascript required, and it is tightly integrated with the Plotly graphing library.

Learn about how to install Dash at

Everywhere in this page that you see, you can display the same figure in a Dash application by passing it to the figure argument of the Graph component from the built-in dash_core_components package like this:

import plotly.graph_objects as go # or as px
fig = go.Figure() # or any Plotly Express function e.g.
# fig.add_trace( ... )
# fig.update_layout( ... )

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()
app.layout = html.Div([

app.run_server(debug=True, use_reloader=False)  # Turn off reloader if inside Jupyter