要更新Plotly圖表的布局,可以使用update_layout()
方法。以下是一個(gè)簡單的示例:
import plotly.express as px
# 創(chuàng)建一個(gè)簡單的散點(diǎn)圖
df = px.data.iris()
fig = px.scatter(df, x='sepal_width', y='sepal_length', color='species')
# 更新圖表的布局
fig.update_layout(
title='Sepal Length vs. Sepal Width',
xaxis_title='Sepal Width',
yaxis_title='Sepal Length',
legend_title='Species'
)
# 顯示圖表
fig.show()
在上面的示例中,我們使用update_layout()
方法來更新圖表的標(biāo)題、x軸標(biāo)題、y軸標(biāo)題和圖例標(biāo)題。您還可以使用其他參數(shù)來自定義圖表的布局,例如設(shè)置圖表的大小、背景色等。詳細(xì)的參數(shù)列表和說明可以參考Plotly的官方文檔。