plotly-resampler icon indicating copy to clipboard operation
plotly-resampler copied to clipboard

fig.update_xaxes(range=[start,end]) and fig.update_yaxes(range=[start,end]) is not working

Open muntakim1 opened this issue 3 years ago • 4 comments

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])

muntakim1 avatar Sep 15 '22 15:09 muntakim1

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

jvdd avatar Sep 15 '22 15:09 jvdd

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)

muntakim1 avatar Sep 15 '22 15:09 muntakim1

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 in fig.update_yaxes(range = [-1.25,1.25], autorange=False) made it work. See my stackoverflow post for more info.

Cheers, Ilian

ilianOptrel avatar Oct 10 '22 07:10 ilianOptrel

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

jvdd avatar Oct 10 '22 19:10 jvdd