You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Plotly图表输出的浏览器标签名设置为指定报表标题?

解决Plotly图表浏览器标签名自定义问题

Plotly确实支持自定义浏览器标签名的功能,你可以通过两种简单方法实现:

方法一:直接修改fig.show()的配置参数

在fig.show()中传入config字典,指定document_title属性即可:

df = df.set_index(['Date'])  # 设置日期为索引

fig = px.pie(df.loc['2022-1-1':'2022-12-31'], values="Payment", names="ExpenseType", title="Household Expenses 2022")
fig.show(config={'document_title': 'Household Expenses 2022'})

方法二:导出为HTML文件时指定标题

如果需要将图表保存为HTML文件,可使用write_html()方法,通过title参数直接设置浏览器标签名:

df = df.set_index(['Date'])  # 设置日期为索引

fig = px.pie(df.loc['2022-1-1':'2022-12-31'], values="Payment", names="ExpenseType", title="Household Expenses 2022")
fig.write_html('household_expenses.html', title='Household Expenses 2022')

打开生成的HTML文件,浏览器标签就会显示你设置的标题。

内容的提问来源于stack exchange,提问作者99Valk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 02:05:25