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

如何在Python中增大Plotly饼图的尺寸?

如何增大Plotly饼图的尺寸?

你可以通过以下几种方法调整Plotly饼图的尺寸,解决显示过小的问题:

方法1:直接设置图表整体布局的宽高

通过update_layout()方法指定width和height参数(单位为像素),直接放大整个图表容器,饼图会随之放大:

import plotly.graph_objects as go

fig = go.Figure(data=[go.Pie(labels=df['index'], values=df['label'])])
# 根据需求调整宽高数值,示例为宽800像素、高600像素
fig.update_layout(width=800, height=600)
fig.show()

方法2:调整饼图的显示区域占比

通过饼图的domain参数,缩小饼图周围的空白边距,让饼图在现有布局中占据更大空间:

import plotly.graph_objects as go

fig = go.Figure(data=[go.Pie(
    labels=df['index'], 
    values=df['label'],
    # x、y轴范围设为0.1到0.9,减少四周空白,数值范围0-1
    domain={'x': [0.1, 0.9], 'y': [0.1, 0.9]}
)])
fig.show()

方法3:结合两种方法(推荐)

同时设置布局宽高和饼图domain参数,既能放大整体容器,又能优化饼图的空间占比:

import plotly.graph_objects as go

fig = go.Figure(data=[go.Pie(
    labels=df['index'], 
    values=df['label'],
    domain={'x': [0.05, 0.95], 'y': [0.05, 0.95]}
)])
fig.update_layout(width=900, height=700)
fig.show()

你可以根据实际需求调整参数数值,直到得到满意的饼图大小。

内容的提问来源于stack exchange,提问作者Seemant Singh

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 04:45:36