Skip to content

Plotly plots don't preserve camera state between re-runs #5530

@blinkybool

Description

@blinkybool

Describe the bug

I want to preserve camera state (zoom + turntable spin) when I change the 3D data I'm plotting in plotly. I think a similar feature was added to fix #1161 for selection and zoom of 2D plots, but that seems to have regressed. This smoke test notebook doesn't behave as intended for me (zoom and selection is lost on slider change): https://github.com/marimo-team/marimo/blob/main/marimo/_smoke_tests/issues/1161.py

Will you submit a PR?

  • Yes

Environment

Details
{
  "marimo": "0.14.10",
  "OS": "Darwin",
  "OS Version": "24.5.0",
  "Processor": "arm",
  "Python Version": "3.11.13",
  "Binaries": {
    "Browser": "--",
    "Node": "--"
  },
  "Dependencies": {
    "click": "8.2.1",
    "docutils": "0.21.2",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.2",
    "markdown": "3.8.2",
    "narwhals": "1.45.0",
    "packaging": "25.0",
    "psutil": "7.0.0",
    "pygments": "2.19.2",
    "pymdown-extensions": "10.16",
    "pyyaml": "6.0.2",
    "starlette": "0.47.1",
    "tomlkit": "0.13.3",
    "typing-extensions": "4.14.0",
    "uvicorn": "0.35.0",
    "websockets": "15.0.1"
  },
  "Optional Dependencies": {
    "loro": "1.5.2"
  },
  "Experimental Flags": {}
}

Code to reproduce

# /// script
# requires-python = ">=3.11"
# dependencies = [
#     "marimo",
#     "numpy==2.3.1",
#     "plotly==6.2.0",
# ]
# ///
import marimo

__generated_with = "0.14.10"
app = marimo.App(width="medium")


@app.cell
def _():
    import marimo as mo
    slider = mo.ui.slider(start=10, stop=100)
    slider
    return mo, slider


@app.cell
def _(mo, slider):
    import numpy as np
    import plotly.graph_objects as go

    x = np.linspace(-5, 5, slider.value)
    y = np.linspace(-5, 5, slider.value)
    x, y = np.meshgrid(x, y)
    z = np.sin(np.sqrt(x**2 + y**2))

    fig = go.Figure(data=[go.Surface(z=z, x=x, y=y)])
    mo.ui.plotly(fig)
    return


if __name__ == "__main__":
    app.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions