Hi @kite_and_code,
Thanks a lot for the kind words! This is a pretty neat example, and yes it is possible to do now with the FigureWidget.
The general idea is to display the data using a plotly histogram trace type. This trace has built-in logic for bin selection based on the number of samples and the spread. Then, listen for changes in the xaxis range and update the data passed to the histogram to include only the points that are present within the current view. This will cause the trace to recompute binning and set the appropriate y-axis range. To get double-click to restore the original view, make sure you explicitly specify the xaxis range of the initial trace.
Hereβs an example
# imports
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
# Generate dataset
x = np.random.randn(5000)
# Create figure and get reference to histogram trace
fig = go.FigureWidget(
[go.Histogram(x=x)],
go.Layout(
title='Dynamic Histogram',
xaxis={'range': [-4, 4],
'title': 'x'},
yaxis={'title': 'count'},
bargap=0.05))
hist = fig.data[0]
# Install xaxis zoom callback
def handle_zoom(xaxis, xrange):
filtered_x = x[np.logical_and(xrange[0] <= x, x <= xrange[1])]
hist.x = filtered_x
fig.layout.xaxis.on_change(handle_zoom, 'range')
# Display FigureWidget
fig
Hope that helps, and have fun!
-Jon