import numpy as np
from bqplot import LinearScale, Hist, Figure, Axis
np.random.seed(0)
x_data = np.random.randn(100)
x_sc = LinearScale()
y_sc = LinearScale()
hist = Hist(sample=x_data, scales={'sample': x_sc, 'count': y_sc})
ax_x = Axis(scale=x_sc, tick_format='0.2f')
ax_y = Axis(scale=y_sc, orientation='vertical')
Figure(marks=[hist], axes=[ax_x, ax_y], padding_y=0)
hist.count
# Changing the number of bins
hist.bins = 20
# normalizing the count
x_sc = LinearScale()
y_sc = LinearScale()
hist = Hist(sample=x_data, scales={'sample': x_sc, 'count': y_sc}, normalized=True)
ax_x = Axis(scale=x_sc, tick_format='0.2f')
ax_y = Axis(scale=y_sc, orientation='vertical')
Figure(marks=[hist], axes=[ax_x, ax_y], padding_y=0)
# changing the color
hist.colors=['orangered']
# stroke and opacity update
hist.stroke = 'orange'
hist.opacities = [0.5] * hist.bins
x_sc = LinearScale()
y_sc = LinearScale()
hist = Hist(sample=x_data, scales={'sample': x_sc, 'count': y_sc})
ax_x = Axis(scale=x_sc, tick_format='0.2f')
ax_y = Axis(scale=y_sc, orientation='vertical')
Figure(marks=[hist], axes=[ax_x, ax_y], padding_y=0)
# count is the number of elements in each interval
hist.count
# mid points are the mid points of each interval
hist.midpoints