Search code examples
pythonchartsfontsformattingplotly

Using multiple font sizes in Plotly chart title (Python)


I have a chart title which spans multiple lines using line breaks.

I'd like to have everything after the first line in a smaller font (effectively a subtitle), but can't figure out a way to do this.

Couldn't see any similar question on here.

import plotly.graph_objs as go
data=[]
layout = go.Layout(title='line1' + '<br>' +  'line2')
fig = go.FigureWidget(data=data, layout=layout)
fig

Any ideas appreciated!


Solution

  • Yes, you can use <span> tags with CSS, like this:

    import plotly.graph_objs as go
    data=[]
    layout = go.Layout(title='line1' + '<br>' +  '<span style="font-size: 12px;">line2</span>')
    fig = go.FigureWidget(data=data, layout=layout)
    fig
    

    enter image description here