在 Plotly 图表标题中使用多种字体大小 (Python)

Using multiple font sizes in Plotly chart title (Python)

我有一个图表标题,它使用换行符跨越多行。

我想在第一行之后的所有内容都使用较小的字体(实际上是副标题),但想不出办法来做到这一点。

在这里看不到任何类似的问题。

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

任何想法表示赞赏!

是的,您可以将 <span> 标签与 CSS 一起使用,如下所示:

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

您可以使用以下方法:

import plotly.express as px
import plotly.data as data

df = data.gapminder()

fig = px.histogram(df, x='continent')

fig.update_layout(
    height=400,
    title=dict(
        text='<b>Life Expectancy - Our World in Data</b>',
        x=0.5,
        y=0.95,
        font=dict(
            family="Arial",
            size=20,
            color='#000000'
        )
    ),
    xaxis_title="<b>Continent</b>",
    yaxis_title='<b>Average Age</b>',
    font=dict(
        family="Courier New, Monospace",
        size=12,
        color='#000000'
    )
)
fig.show()

]1