{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from bqplot import LinearScale, Hist, Figure, Axis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Basic Histogram" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "np.random.seed(0)\n", "x_data = np.random.randn(100)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x_sc = LinearScale()\n", "y_sc = LinearScale()\n", "\n", "hist = Hist(sample=x_data, scales={'sample': x_sc, 'count': y_sc})\n", "ax_x = Axis(scale=x_sc, tick_format='0.2f')\n", "ax_y = Axis(scale=y_sc, orientation='vertical')\n", "\n", "Figure(marks=[hist], axes=[ax_x, ax_y], padding_y=0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hist.count" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Changing the number of bins\n", "hist.bins = 20" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Properties of Histogram" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# normalizing the count\n", "\n", "x_sc = LinearScale()\n", "y_sc = LinearScale()\n", "\n", "hist = Hist(sample=x_data, scales={'sample': x_sc, 'count': y_sc}, normalized=True)\n", "ax_x = Axis(scale=x_sc, tick_format='0.2f')\n", "ax_y = Axis(scale=y_sc, orientation='vertical')\n", "\n", "Figure(marks=[hist], axes=[ax_x, ax_y], padding_y=0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# changing the color\n", "hist.colors=['orangered']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# stroke and opacity update\n", "hist.stroke = 'orange'\n", "hist.opacities = [0.5] * hist.bins" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read-only properties of Histogram" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x_sc = LinearScale()\n", "y_sc = LinearScale()\n", "\n", "hist = Hist(sample=x_data, scales={'sample': x_sc, 'count': y_sc})\n", "ax_x = Axis(scale=x_sc, tick_format='0.2f')\n", "ax_y = Axis(scale=y_sc, orientation='vertical')\n", "\n", "Figure(marks=[hist], axes=[ax_x, ax_y], padding_y=0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# count is the number of elements in each interval\n", "hist.count" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# mid points are the mid points of each interval\n", "hist.midpoints" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 1 }