Last active
March 29, 2022 20:51
-
-
Save 8080labs/276b58f1e57db076b679082faa8de754 to your computer and use it in GitHub Desktop.
plotly_rebinable_histogram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly.graph_objs as go | |
import ipywidgets as widgets | |
def rebinnable_interactive_histogram(series, initial_bin_width=10): | |
figure_widget = go.FigureWidget( | |
data=[go.Histogram(x=series, xbins={"size": initial_bin_width})] | |
) | |
bin_slider = widgets.FloatSlider( | |
value=initial_bin_width, | |
min=1, | |
max=30, | |
step=1, | |
description="Bin width:", | |
readout_format=".0f", # display as integer | |
) | |
histogram_object = figure_widget.data[0] | |
def set_bin_size(change): | |
histogram_object.xbins = {"size": change["new"]} | |
bin_slider.observe(set_bin_size, names="value") | |
output_widget = widgets.VBox([figure_widget, bin_slider]) | |
return output_widget | |
rebinnable_interactive_histogram(df, "air_time") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment