-
-
Notifications
You must be signed in to change notification settings - Fork 68
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] Legend does not display when trace has no real data points #293
Comments
Hi @mhangaard, Thank you for providing such a detailed report. 👏🏼 I believe your issue is caused by the Given that your "empty" trace is not a large trace, TLDR: workarounduse the Working example ⬇️ : import numpy as np
import pandas as pd
import plotly.graph_objects as go
from plotly_resampler import register_plotly_resampler, unregister_plotly_resampler
# comment out this line to get native plotly behavior
register_plotly_resampler(mode="auto", default_n_shown_samples=100)
n = 10000
x = np.arange(n)
x_time = pd.date_range("2020-01-01", freq="1s", periods=len(x))
noisy_sine = (3 + np.sin(x / 2000) + np.random.randn(n) / 10) * x / (n / 4)
fig = go.Figure()
fig.add_trace(
go.Scattergl(x=[None], y=[None], name="yp2", showlegend=True, legendgroup="yp2"),
# NOTE: I added this argument (this is not that loosely coupled, but it works for plotly-resampler=0.9.2)
check_nans=False,
)
fig.add_trace(
go.Scattergl(y=noisy_sine + 2, name="yp2", showlegend=False, legendgroup="yp2")
)
fig.add_trace(go.Scattergl(y=noisy_sine - 3, name="ym1"))
fig Kind regards, |
related: #294 |
It can be argued that Plotly should have more options to customize the legend items, instead of having to hack the legend using an empty trace. |
|
Describe the bug 🖍️
When plotting a trace with empty x and y, the legend does not display. Plotly has limited options for customizing the legend, so an empty trace is useful in combination with legendgroup to customize the legend.
Reproducing the bug 🔍
Expected behavior 🔧
Native plotly behavior is that the legend of the empty trace appears (blue "yp2" on this screenshot). I can rely on the legend group to toggle the red trace by clicking the "yp2" legend.
I would probably not be able to get the prefixing and suffixing, on the other trace in same legendgroup, but that's also ok.
Environment information:
Additional context
I have the same behavior in a Dash app.
The text was updated successfully, but these errors were encountered: