Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] spikes are removed when clicking on reset axis #290

Open
jonasvdd opened this issue Jan 14, 2024 · 0 comments
Open

[BUG] spikes are removed when clicking on reset axis #290

jonasvdd opened this issue Jan 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jonasvdd
Copy link
Member

Describe the bug πŸ–οΈ
(when using a FigureResampler, with hover mode x-unified) the vertical spikes are removed when clicking reset-axis.

Reproducing the bug πŸ”

Please provide steps & minimal viable code to reproduce the behavior.

import numpy as np
import plotly.graph_objects as go
from dash import Dash, Input, Output, callback_context, dcc, html, no_update

from plotly_resampler import FigureResampler

# Data that will be used for the plotly-resampler figures
x = np.arange(2_000_000)
noisy_sin = (3 + np.sin(x / 200) + np.random.randn(len(x)) / 10) * x / 1_000


# --------------------------------------Globals ---------------------------------------
app = Dash(__name__)
fig: FigureResampler = FigureResampler()
# NOTE: in this example, this reference to a FigureResampler is essential to preserve
# throughout the whole dash app! If your dash app wants to create a new go.Figure(),
# you should not construct a new FigureResampler object, but replace the figure of this
# FigureResampler object by using the FigureResampler.replace() method.

app.layout = html.Div(
    [
        html.H1("plotly-resampler global variable", style={"textAlign": "center"}),
        html.Button("plot chart", id="plot-button", n_clicks=0),
        html.Hr(),
        # The graph object  - which we will empower with plotly-resampler
        dcc.Graph(id="graph-id"),
    ]
)


# ------------------------------------ DASH logic -------------------------------------
# The callback used to construct and store the graph's data on the serverside
@app.callback(
    Output("graph-id", "figure"),
    Input("plot-button", "n_clicks"),
    prevent_initial_call=True,
)
def plot_graph(n_clicks):
    ctx = callback_context
    if len(ctx.triggered) and "plot-button" in ctx.triggered[0]["prop_id"]:
        # Note how the replace method is used here on the global figure object
        global fig
        if len(fig.data):
            # Replace the figure with an empty one to clear the graph
            fig.replace(go.Figure())
        fig.add_trace(go.Scattergl(name="log"), hf_x=x, hf_y=noisy_sin * 0.9999995**x)
        fig.add_trace(go.Scattergl(name="exp"), hf_x=x, hf_y=noisy_sin * 1.000002**x)
        fig.update_layout(hovermode="x unified")
        fig.update_xaxes(showspikes=True)
        return fig
    else:
        return no_update


# The plotly-resampler callback to update the graph after a relayout event (= zoom/pan)
fig.register_update_graph_callback(app=app, graph_id="graph-id")

# --------------------------------- Running the app ---------------------------------
if __name__ == "__main__":
    app.run_server(debug=True, port=9022)

Giving this information makes it tremendously easier to work on your issue!
spike_xaxis

Expected behavior πŸ”§

The spikes should remain visible visible.

@jonasvdd jonasvdd added the bug Something isn't working label Jan 14, 2024
@jonasvdd jonasvdd assigned jonasvdd and unassigned jonasvdd Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant