8

I need to create a plot on plotly with a newline. Preferably the text on the top is larger than the second line, but not necessary.

fig.update_layout(
    title=go.layout.Title(
        text=title,
        xref="paper",
        x=0.5,
    ),

For the title I have tried

title = "Hello \n World"
title = "Hello" + "\n" + "World"
title = "$Hello \\ World$"
title = "$Hello \newline World$"

All run without error, but the newline is ignored.

I am not sure how to implement this. Thank you for the help.

1 Answers1

25

You can add a <br> tag to the title and it will be interpreted as an HTML line break. This is supported by this doc. You can see the result in the following example:

from dash import Dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div(children=[
    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5],
                    'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data <br> Visualization'
            }
        }
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)

enter image description here

ncasale
  • 769
  • 6
  • 10