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

如何更改Plotly subplot的起始单元格索引顺序?

实现Plotly子图索引从左下角开始的方法

在Plotly中创建子图时,默认索引起始位置是左上角,要改为从左下角开始,只需在调用make_subplots()时指定start_cell="bottom-left"参数即可。

代码示例

import plotly.graph_objects as go
from plotly.subplots import make_subplots

# 创建3行2列的子图,设置索引从左下角开始
fig = make_subplots(
    rows=3, cols=2,
    start_cell="bottom-left"  # 核心参数,指定起始单元格位置
)

# 为每个子图添加示例数据
for row in range(1, 4):
    for col in range(1, 3):
        fig.add_trace(
            go.Scatter(x=[1, 2, 3], y=[4, 5, 6], name=f"子图 ({row}, {col})"),
            row=row, col=col
        )

# 调整布局并展示图表
fig.update_layout(height=600, width=800, title_text="子图索引从左下角起始")
fig.show()

参数说明

  • start_cell的可选值为"top-left"(默认)和"bottom-left":
    • 默认"top-left"时,子图的(1,1)位于左上角,行号从上到下递增;
    • 设置为"bottom-left"后,子图的(1,1)位于左下角,行号从下到上递增。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 01:52:43