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

如何在Plotly(Python)的3D散点图中调整轴标题与轴刻度的间距?

调整Plotly 3D散点图轴标题与刻度的间距

要增大X、Y、Z轴标题和对应刻度之间的间距,只需在每个轴的配置中添加title_standoff参数,该参数以像素为单位定义标题与刻度的距离,数值越大间距越宽,可根据需求灵活调整。

修改后的完整代码如下:

import plotly.graph_objects as go

# 准备数据
x = [1,2,3,4,5]
y = [2,4,6,8,10]
z = [2,4,6,8,10]

# 创建图表
fig = go.Figure(data=[go.Scatter3d(x=x, y=y, z=z, mode='markers')])

# 配置坐标轴与布局
fig.update_layout(
    title='3D Scatterplot',
    scene = dict(
        xaxis = dict(
            title='X Axis',
            title_standoff=25  # 调整X轴标题与刻度的间距
        ),
        yaxis = dict(
            title='Y Axis',
            title_standoff=25  # 调整Y轴标题与刻度的间距
        ),
        zaxis = dict(
            title='Z Axis',
            title_standoff=25  # 调整Z轴标题与刻度的间距
        )
    )
)

# 显示图表
fig.show()

你可以根据实际视觉效果修改title_standoff的数值(比如20、30),直到得到满意的间距。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 19:27:22