Help with client-side Plotly layout attributes

Hi @paul.scheidt and welcome to the forum,

Sometimes the plotly docs show this, sometimes not.

3d scatter plots in Python

When the docs don’t come up with much, creating something using plotly express, and then printing out the figure helps


import plotly.express as px
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
              color='species')
print(fig.layout)

Leads to:


Layout({
    'legend': {'title': {'text': 'species'}, 'tracegroupgap': 0},
    'margin': {'t': 60},
    'scene': {'domain': {'x': [0.0, 1.0], 'y': [0.0, 1.0]},
              'xaxis': {'title': {'text': 'sepal_length'}},
              'yaxis': {'title': {'text': 'sepal_width'}},
              'zaxis': {'title': {'text': 'petal_width'}}},
    'template': '...'
})

So we can create what we want:

scene = go.layout.Scene(
    domain={"x": [0.0, 1.0], "y": [0.0, 1.0]},
    xaxis={"title": {"text": "sepal_length"}},
    yaxis={"title": {"text": "sepal_width"}},
    zaxis={"title": {"text": "petal_width"}},
)

self.plot_1.layout = go.Layout(scene=scene)
2 Likes