| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "code", |
| 5 |
"execution_count": 1, |
| 6 |
"metadata": {}, |
| 7 |
"outputs": [], |
| 8 |
"source": [ |
| 9 |
"import numpy as np\n", |
| 10 |
"import bqplot.pyplot as plt" |
| 11 |
] |
| 12 |
}, |
| 13 |
{ |
| 14 |
"cell_type": "markdown", |
| 15 |
"metadata": {}, |
| 16 |
"source": [ |
| 17 |
"## Basic Histogram" |
| 18 |
] |
| 19 |
}, |
| 20 |
{ |
| 21 |
"cell_type": "code", |
| 22 |
"execution_count": 2, |
| 23 |
"metadata": {}, |
| 24 |
"outputs": [], |
| 25 |
"source": [ |
| 26 |
"np.random.seed(0)\n", |
| 27 |
"x_data = np.random.randn(100)" |
| 28 |
] |
| 29 |
}, |
| 30 |
{ |
| 31 |
"cell_type": "code", |
| 32 |
"execution_count": 3, |
| 33 |
"metadata": {}, |
| 34 |
"outputs": [ |
| 35 |
{ |
| 36 |
"data": { |
| 37 |
"application/vnd.jupyter.widget-view+json": { |
| 38 |
"model_id": "a17eee64f6ef4796beb31ddb369c40a3", |
| 39 |
"version_major": 2, |
| 40 |
"version_minor": 0 |
| 41 |
}, |
| 42 |
"text/plain": [ |
| 43 |
"Figure(axes=[Axis(orientation='vertical', scale=LinearScale()), Axis(scale=LinearScale())], fig_margin={'top':…" |
| 44 |
] |
| 45 |
}, |
| 46 |
"metadata": {}, |
| 47 |
"output_type": "display_data" |
| 48 |
} |
| 49 |
], |
| 50 |
"source": [ |
| 51 |
"fig = plt.figure(padding_y=0)\n", |
| 52 |
"hist = plt.hist(x_data)\n", |
| 53 |
"fig" |
| 54 |
] |
| 55 |
}, |
| 56 |
{ |
| 57 |
"cell_type": "code", |
| 58 |
"execution_count": 4, |
| 59 |
"metadata": {}, |
| 60 |
"outputs": [ |
| 61 |
{ |
| 62 |
"data": { |
| 63 |
"text/plain": [ |
| 64 |
"array([], dtype=float64)" |
| 65 |
] |
| 66 |
}, |
| 67 |
"execution_count": 4, |
| 68 |
"metadata": {}, |
| 69 |
"output_type": "execute_result" |
| 70 |
} |
| 71 |
], |
| 72 |
"source": [ |
| 73 |
"hist.count" |
| 74 |
] |
| 75 |
}, |
| 76 |
{ |
| 77 |
"cell_type": "code", |
| 78 |
"execution_count": 5, |
| 79 |
"metadata": {}, |
| 80 |
"outputs": [], |
| 81 |
"source": [ |
| 82 |
"# Changing the number of bins\n", |
| 83 |
"hist.bins = 20" |
| 84 |
] |
| 85 |
}, |
| 86 |
{ |
| 87 |
"cell_type": "markdown", |
| 88 |
"metadata": {}, |
| 89 |
"source": [ |
| 90 |
"## Properties of Histogram" |
| 91 |
] |
| 92 |
}, |
| 93 |
{ |
| 94 |
"cell_type": "code", |
| 95 |
"execution_count": 6, |
| 96 |
"metadata": {}, |
| 97 |
"outputs": [ |
| 98 |
{ |
| 99 |
"data": { |
| 100 |
"application/vnd.jupyter.widget-view+json": { |
| 101 |
"model_id": "808738390285401bb60f4a0c3dc2888d", |
| 102 |
"version_major": 2, |
| 103 |
"version_minor": 0 |
| 104 |
}, |
| 105 |
"text/plain": [ |
| 106 |
"Figure(axes=[Axis(orientation='vertical', scale=LinearScale()), Axis(scale=LinearScale())], fig_margin={'top':…" |
| 107 |
] |
| 108 |
}, |
| 109 |
"metadata": {}, |
| 110 |
"output_type": "display_data" |
| 111 |
} |
| 112 |
], |
| 113 |
"source": [ |
| 114 |
"# normalizing the count\n", |
| 115 |
"fig = plt.figure(padding_y=0)\n", |
| 116 |
"hist = plt.hist(x_data, normalized=True)\n", |
| 117 |
"fig" |
| 118 |
] |
| 119 |
}, |
| 120 |
{ |
| 121 |
"cell_type": "code", |
| 122 |
"execution_count": 7, |
| 123 |
"metadata": {}, |
| 124 |
"outputs": [], |
| 125 |
"source": [ |
| 126 |
"# changing the color\n", |
| 127 |
"hist.colors=['orangered']" |
| 128 |
] |
| 129 |
}, |
| 130 |
{ |
| 131 |
"cell_type": "code", |
| 132 |
"execution_count": 8, |
| 133 |
"metadata": {}, |
| 134 |
"outputs": [], |
| 135 |
"source": [ |
| 136 |
"# stroke and opacity update\n", |
| 137 |
"hist.stroke = 'orange'\n", |
| 138 |
"hist.opacities = [0.5] * hist.bins" |
| 139 |
] |
| 140 |
}, |
| 141 |
{ |
| 142 |
"cell_type": "markdown", |
| 143 |
"metadata": {}, |
| 144 |
"source": [ |
| 145 |
"## Read-only properties of Histogram" |
| 146 |
] |
| 147 |
}, |
| 148 |
{ |
| 149 |
"cell_type": "code", |
| 150 |
"execution_count": 9, |
| 151 |
"metadata": {}, |
| 152 |
"outputs": [ |
| 153 |
{ |
| 154 |
"data": { |
| 155 |
"application/vnd.jupyter.widget-view+json": { |
| 156 |
"model_id": "61970e249cde43a980740559c6165c4b", |
| 157 |
"version_major": 2, |
| 158 |
"version_minor": 0 |
| 159 |
}, |
| 160 |
"text/plain": [ |
| 161 |
"Figure(axes=[Axis(orientation='vertical', scale=LinearScale()), Axis(scale=LinearScale())], fig_margin={'top':…" |
| 162 |
] |
| 163 |
}, |
| 164 |
"metadata": {}, |
| 165 |
"output_type": "display_data" |
| 166 |
} |
| 167 |
], |
| 168 |
"source": [ |
| 169 |
"fig = plt.figure(padding_y=0)\n", |
| 170 |
"hist = plt.hist(x_data, normalized=True)\n", |
| 171 |
"fig" |
| 172 |
] |
| 173 |
}, |
| 174 |
{ |
| 175 |
"cell_type": "code", |
| 176 |
"execution_count": 10, |
| 177 |
"metadata": {}, |
| 178 |
"outputs": [ |
| 179 |
{ |
| 180 |
"data": { |
| 181 |
"text/plain": [ |
| 182 |
"array([], dtype=float64)" |
| 183 |
] |
| 184 |
}, |
| 185 |
"execution_count": 10, |
| 186 |
"metadata": {}, |
| 187 |
"output_type": "execute_result" |
| 188 |
} |
| 189 |
], |
| 190 |
"source": [ |
| 191 |
"# count is the number of elements in each interval\n", |
| 192 |
"hist.count" |
| 193 |
] |
| 194 |
}, |
| 195 |
{ |
| 196 |
"cell_type": "code", |
| 197 |
"execution_count": 11, |
| 198 |
"metadata": {}, |
| 199 |
"outputs": [ |
| 200 |
{ |
| 201 |
"data": { |
| 202 |
"text/plain": [ |
| 203 |
"[]" |
| 204 |
] |
| 205 |
}, |
| 206 |
"execution_count": 11, |
| 207 |
"metadata": {}, |
| 208 |
"output_type": "execute_result" |
| 209 |
} |
| 210 |
], |
| 211 |
"source": [ |
| 212 |
"# mid points are the mid points of each interval\n", |
| 213 |
"hist.midpoints" |
| 214 |
] |
| 215 |
} |
| 216 |
], |
| 217 |
"metadata": { |
| 218 |
"kernelspec": { |
| 219 |
"display_name": "Python 3", |
| 220 |
"language": "python", |
| 221 |
"name": "python3" |
| 222 |
}, |
| 223 |
"language_info": { |
| 224 |
"codemirror_mode": { |
| 225 |
"name": "ipython", |
| 226 |
"version": 3 |
| 227 |
}, |
| 228 |
"file_extension": ".py", |
| 229 |
"mimetype": "text/x-python", |
| 230 |
"name": "python", |
| 231 |
"nbconvert_exporter": "python", |
| 232 |
"pygments_lexer": "ipython3", |
| 233 |
"version": "3.7.6" |
| 234 |
} |
| 235 |
}, |
| 236 |
"nbformat": 4, |
| 237 |
"nbformat_minor": 1 |
| 238 |
} |