In [ ]:
import numpy as np
from bqplot import *

Basic Histogram


In [ ]:
np.random.seed(0)
x_data = np.random.randn(100)

In [ ]:
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)

In [ ]:
hist.count

In [ ]:
# Changing the number of bins
hist.bins = 20

Properties of Histogram


In [ ]:
# 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)

In [ ]:
# changing the color
hist.colors=['orangered']

In [ ]:
# stroke and opacity update
hist.stroke = 'orange'
hist.opacities = [0.5] * hist.bins

Read-only properties of Histogram


In [ ]:
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)

In [ ]:
# count is the number of elements in each interval
hist.count

In [ ]:
# mid points are the mid points of each interval
hist.midpoints

In [ ]: