plotly / plotly/plotly.js

UI revision does not work while specifying projection type

Open
#6,840 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2
Dominant language
JavaScript
Stars
18.3k
Forks
2k
Avg merge
2d 12h
Merged PRs (30d)
28

Description

i’ve been unable to make uirevision to work while using the orthographic projection on 3D scatter plot using graph object.
here’s a simplified example (i'm not as familiar with JS , therefore the example is in python.) :

import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import pandas as pd
from numpy.random import randn
# Sample data
data = {
    'sepal_width': [3.5, 3.0, 3.2, 3.1, 3.6],
    'sepal_length': [5.1, 4.9, 4.7, 4.6, 5.0],
    'petal_length': [1.4, 1.4, 1.3, 1.5, 1.4],
}
data2 = {
    'sepal_width': [3.5, 3.0, 3.2, 3.1, 3.6]*3,
    'sepal_length': [5.1, 4.9, 4.7, 4.6, 5.0]*2,
    'petal_length': [1.4, 1.4, 1.3, 1.5, 1.4]*1,
}
df = pd.DataFrame(data)

# Initial Figure
scatter_figure = go.Figure()
scatter_figure.layout.uirevision = True
scatter_figure.layout.scene.camera.projection.type = 'orthographic'
# Add 3D Scatter Plot Trace
scatter_figure.add_trace(
    go.Scatter3d(
        x=df['sepal_width'],
        y=df['sepal_length'],
        z=df['petal_length'],
        mode='markers',
        marker=dict(
            size=12,
            opacity=0.7,
        ),
        scene='scene',
    )
)

# Dash app
app = dash.Dash(__name__)

# Layout
app.layout = html.Div([
    dcc.Graph(
        id='scatter-plot',
        figure=scatter_figure,
    ),
    dcc.Checklist(
        id='toggle-checklist',
        options=[
            {'label': 'Toggle Plot', 'value': 'toggle'}
        ],
        value=['toggle'],
    ),
])

# Callback to toggle plot visibility
@app.callback(
    Output('scatter-plot', 'figure'),
    [Input('toggle-checklist', 'value')]
)
def toggle_plot(value):
    if 'toggle' in value:
        # If 'toggle' is in the value, show the plot
        return scatter_figure
    else:
        df = data2
        scatter_figure.add_trace(
            go.Scatter3d(
                x=df['sepal_width'],
                y=df['sepal_length'],
                z=df['petal_length'],
                mode='markers',
                marker=dict(
                    size=12,
                    opacity=0.7,
                ),
                scene='scene',
            )
        )
        return scatter_figure

# Run the app
if __name__ == '__main__':
    app.run_server(debug=True,port = 8078)

every time I'm toggling the check box the view completely reversed to its original position, and only when I'm specifying projection to be orthographic , works perfectly on perspective.

I'd really appeiciate you looking into this :)
Happy New Year and thanks in advance.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Dash/Python reproduction, focusing on the 3D scatter plot's uirevision behavior when scene.camera.projection.type is set to orthographic. Compare toggling the checklist under orthographic and perspective projections; done means the camera view remains in its current position when the plot is toggled.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.