plotly-resampler
plotly-resampler copied to clipboard
fig.update_xaxes(range=[start,end]) and fig.update_yaxes(range=[start,end]) is not working
Here is my code: I am trying to show only the selected range values using the custom slider.
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from plotly_resampler import FigureResampler
x = np.arange(2_000)
noisy_sin = (3 + np.sin(x / 200) + np.random.randn(len(x)) / 10) * x / 1_00
fig = FigureResampler(go.Figure())
fig.add_trace(go.Scattergl(name="exp",x=x,y=noisy_sin))
fig.update_layout(xaxis_range=[20,300])
Hey!
This is indeed a bug, nice catch :+1: We should provide exactly the same behavior as plotly - which is not the case here.
A quick fix for now is setting autorange to False for the xaxes; fig.update_xaxes(autorange=False) . Does this work for you?
In the meantime I'll try to find a more permanent fix for this bug in the code :)
Cheers, Jeroen
Hi, Thanks for the comment. I tried earlier but it wasn't working. probably I use the update_layout, Now it's working. thanks agian.
fig.update_xaxes(autorange=False)
I noticed the same issue with scaling the y-axis. Neither of the following options work for me:
fig.update_layout(yaxis_range=[-1,1])fig.update(layout_yaxis_range = [-1,1])fig.update_yaxes(range = [-1,1]). However, setting autoscale to False infig.update_yaxes(range = [-1.25,1.25], autorange=False)made it work. See my stackoverflow post for more info.
Cheers, Ilian
Thx for sharing your issue as well @ilianOptrel!
I have been quite busy last month, but I'll take a closer look at this bug somewhere this week :)
At first sight this bug does not occur when using the FigureWidgetResampler. For example the following code should work fine (in an IPython environment, such as Jupyter);
import numpy as np
import plotly.graph_objects as go
from plotly_resampler import FigureWidgetResampler
x = np.arange(2_000)
noisy_sin = (3 + np.sin(x / 200) + np.random.randn(len(x)) / 10) * x / 1_00
fig = FigureWidgetResampler(default_n_shown_samples=20)
fig.add_trace(go.Scattergl(name="exp",x=x,y=noisy_sin))
fig.update_layout(xaxis_range=[200,300])
fig.update_layout(yaxis_range=[0,30])
fig