{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import bqplot.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Basic Histogram" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "np.random.seed(0)\n", "x_data = np.random.randn(100)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a17eee64f6ef4796beb31ddb369c40a3", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Figure(axes=[Axis(orientation='vertical', scale=LinearScale()), Axis(scale=LinearScale())], fig_margin={'top':…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = plt.figure(padding_y=0)\n", "hist = plt.hist(x_data)\n", "fig" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([], dtype=float64)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hist.count" ] }, { "cell_type": "code", "execution_count": 5, "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": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "808738390285401bb60f4a0c3dc2888d", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Figure(axes=[Axis(orientation='vertical', scale=LinearScale()), Axis(scale=LinearScale())], fig_margin={'top':…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# normalizing the count\n", "fig = plt.figure(padding_y=0)\n", "hist = plt.hist(x_data, normalized=True)\n", "fig" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# changing the color\n", "hist.colors=['orangered']" ] }, { "cell_type": "code", "execution_count": 8, "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": 9, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "61970e249cde43a980740559c6165c4b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Figure(axes=[Axis(orientation='vertical', scale=LinearScale()), Axis(scale=LinearScale())], fig_margin={'top':…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = plt.figure(padding_y=0)\n", "hist = plt.hist(x_data, normalized=True)\n", "fig" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([], dtype=float64)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# count is the number of elements in each interval\n", "hist.count" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "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 }