Skip to content

Latest commit

 

History

History
93 lines (79 loc) · 2.44 KB

figure-labels.md

File metadata and controls

93 lines (79 loc) · 2.44 KB
jupyter
jupytext kernelspec language_info plotly
notebook_metadata_filter text_representation
all
extension format_name format_version jupytext_version
.md
markdown
1.1
1.2.1
display_name language name
Python 3
python
python3
codemirror_mode file_extension mimetype name nbconvert_exporter pygments_lexer version
name version
ipython
3
.py
text/x-python
python
python
ipython3
3.7.3
description display_as language layout name order permalink redirect_from thumbnail
How to set the global font, title, legend-entries, and axis-titles in python.
file_settings
python
base
Setting the Font, Title, Legend Entries, and Axis Titles
12
python/figure-labels/
python/font/
thumbnail/figure-labels.png
import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Scatter(
    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
))


fig.add_trace(go.Scatter(
    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"
))

fig.update_layout(
    title="Plot Title",
    xaxis_title="x Axis Title",
    yaxis_title="y Axis Title",
    font=dict(
        family="Courier New, monospace",
        size=18,
        color="#7f7f7f"
    )
)

fig.show()

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.

import plotly.graph_objects as go

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

fig.update_layout(
    title={
        'text': "Plot Title",
        'y':0.9,
        'x':0.5,
        'xanchor': 'center',
        'yanchor': 'top'})

fig.show()

Reference

See https://plotly.com/python/reference/#layout for more information!