Search code examples
python-3.xjupyter-notebookplotlyplotly-pythongraph-visualization

Can't scale subplot y-axis in plotly with plotly_reasampler registered


I have the problem that somehow, if I use predict-idlab's awesome plotly_resampler package for plotting large datasets with plotly, I can't properly scale the y-axis of all subplots in a figure. Consider the following code

from plotly_resampler import register_plotly_resampler, unregister_plotly_resampler
from plotly.subplots import make_subplots
import plotly.graph_objects as go

register_plotly_resampler(mode="auto", default_n_shown_samples=10000)

channels = [([1,2,3],[-10, 0, 10]), ([1,2,3], [5,4,0])]
fig = make_subplots(rows=len(channels), cols=1, subplot_titles=['subplot1', 'subplot2'], shared_xaxes=True)
for j, channel in enumerate(channels):
    x = channel[0]
    y = channel[1]
    fig.add_trace(go.Scattergl(x=x, y=y), row=j+1, col=1)
    fig.update_xaxes(title_text='x', row=j+1, col=1)
    fig.update_yaxes(title_text='y', range=[-1.25, 1.25], row=j+1, col=1)
fig.update_layout(title_text='Plot Title')
display(fig)
        
unregister_plotly_resampler()

This results in the following plot: enter image description here

So as can be seen the y-axis of the first subfigure is not scaled to the desired range. However, if I remove the register/unregister_plotly_resampler() lines, everything works like a charm:

enter image description here

What's the matter here?

EDIT=========================

I found a workaround: If the y-axis is formatted with fig.update_yaxes(range = [-1.5,1.5]) or fig.update(layout_yaxis_range = [-1.5,1.5]) before running register_plotly_resampler(), everything works fine.


Solution

  • in the meantime we fixed the known bug and made a new release.

    Installing any plotly-resampler version >= 8.2.0, will result in expected behavior (similar to the behavior of plotly) - see illustration below

    example of scaling y-axis with plotly-resampler v8.2.0