Search code examples
plotly

Plotly layout Z-axes config


How to set height of Z axes in graph_object.layout

I tried using

zaxis: {
    showgrid: true,
    zeroline: true,
    linecolor: '#d7d7d7',
    linewidth: 1,
    tickfont: {size: 12},
    ticks: 'outside',
    tickcolor: '#d7d7d7',
    tickformat: '.0f',
    scaleanchor: 'x',
    range: 5,
    rangemode: 'normal',
    dtick: 'tick0'
}

Solution

  • You need to set aspectmode and aspectratio. For example:

    import plotly.graph_objects as go
    import numpy as np
    
    x = np.random.uniform(0, 1, 100)
    y = np.random.uniform(0, 1, 100)
    z = np.random.uniform(0, 1, 100)
    fig1 = go.Figure([
        go.Scatter3d(x=x, y=y, z=z, marker_size=3)
    ])
    fig2 = go.Figure([
        go.Scatter3d(x=x, y=y, z=z, marker_size=3)
    ], layout={"scene": {"aspectmode": "manual", "aspectratio": {"x": 1, "y": 1, "z": 0.25}}})
    

    enter image description here