| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "code", |
| 5 |
"execution_count": null, |
| 6 |
"metadata": {}, |
| 7 |
"outputs": [], |
| 8 |
"source": [ |
| 9 |
"import numpy as np\n", |
| 10 |
"from bqplot import LinearScale, Hist, Figure, Axis" |
| 11 |
] |
| 12 |
}, |
| 13 |
{ |
| 14 |
"cell_type": "markdown", |
| 15 |
"metadata": {}, |
| 16 |
"source": [ |
| 17 |
"## Basic Histogram" |
| 18 |
] |
| 19 |
}, |
| 20 |
{ |
| 21 |
"cell_type": "code", |
| 22 |
"execution_count": null, |
| 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": null, |
| 33 |
"metadata": {}, |
| 34 |
"outputs": [], |
| 35 |
"source": [ |
| 36 |
"x_sc = LinearScale()\n", |
| 37 |
"y_sc = LinearScale()\n", |
| 38 |
"\n", |
| 39 |
"hist = Hist(sample=x_data, scales={'sample': x_sc, 'count': y_sc})\n", |
| 40 |
"ax_x = Axis(scale=x_sc, tick_format='0.2f')\n", |
| 41 |
"ax_y = Axis(scale=y_sc, orientation='vertical')\n", |
| 42 |
"\n", |
| 43 |
"Figure(marks=[hist], axes=[ax_x, ax_y], padding_y=0)" |
| 44 |
] |
| 45 |
}, |
| 46 |
{ |
| 47 |
"cell_type": "code", |
| 48 |
"execution_count": null, |
| 49 |
"metadata": {}, |
| 50 |
"outputs": [], |
| 51 |
"source": [ |
| 52 |
"hist.count" |
| 53 |
] |
| 54 |
}, |
| 55 |
{ |
| 56 |
"cell_type": "code", |
| 57 |
"execution_count": null, |
| 58 |
"metadata": {}, |
| 59 |
"outputs": [], |
| 60 |
"source": [ |
| 61 |
"# Changing the number of bins\n", |
| 62 |
"hist.bins = 20" |
| 63 |
] |
| 64 |
}, |
| 65 |
{ |
| 66 |
"cell_type": "markdown", |
| 67 |
"metadata": {}, |
| 68 |
"source": [ |
| 69 |
"## Properties of Histogram" |
| 70 |
] |
| 71 |
}, |
| 72 |
{ |
| 73 |
"cell_type": "code", |
| 74 |
"execution_count": null, |
| 75 |
"metadata": {}, |
| 76 |
"outputs": [], |
| 77 |
"source": [ |
| 78 |
"# normalizing the count\n", |
| 79 |
"\n", |
| 80 |
"x_sc = LinearScale()\n", |
| 81 |
"y_sc = LinearScale()\n", |
| 82 |
"\n", |
| 83 |
"hist = Hist(sample=x_data, scales={'sample': x_sc, 'count': y_sc}, normalized=True)\n", |
| 84 |
"ax_x = Axis(scale=x_sc, tick_format='0.2f')\n", |
| 85 |
"ax_y = Axis(scale=y_sc, orientation='vertical')\n", |
| 86 |
"\n", |
| 87 |
"Figure(marks=[hist], axes=[ax_x, ax_y], padding_y=0)" |
| 88 |
] |
| 89 |
}, |
| 90 |
{ |
| 91 |
"cell_type": "code", |
| 92 |
"execution_count": null, |
| 93 |
"metadata": {}, |
| 94 |
"outputs": [], |
| 95 |
"source": [ |
| 96 |
"# changing the color\n", |
| 97 |
"hist.colors=['orangered']" |
| 98 |
] |
| 99 |
}, |
| 100 |
{ |
| 101 |
"cell_type": "code", |
| 102 |
"execution_count": null, |
| 103 |
"metadata": {}, |
| 104 |
"outputs": [], |
| 105 |
"source": [ |
| 106 |
"# stroke and opacity update\n", |
| 107 |
"hist.stroke = 'orange'\n", |
| 108 |
"hist.opacities = [0.5] * hist.bins" |
| 109 |
] |
| 110 |
}, |
| 111 |
{ |
| 112 |
"cell_type": "markdown", |
| 113 |
"metadata": {}, |
| 114 |
"source": [ |
| 115 |
"## Read-only properties of Histogram" |
| 116 |
] |
| 117 |
}, |
| 118 |
{ |
| 119 |
"cell_type": "code", |
| 120 |
"execution_count": null, |
| 121 |
"metadata": {}, |
| 122 |
"outputs": [], |
| 123 |
"source": [ |
| 124 |
"x_sc = LinearScale()\n", |
| 125 |
"y_sc = LinearScale()\n", |
| 126 |
"\n", |
| 127 |
"hist = Hist(sample=x_data, scales={'sample': x_sc, 'count': y_sc})\n", |
| 128 |
"ax_x = Axis(scale=x_sc, tick_format='0.2f')\n", |
| 129 |
"ax_y = Axis(scale=y_sc, orientation='vertical')\n", |
| 130 |
"\n", |
| 131 |
"Figure(marks=[hist], axes=[ax_x, ax_y], padding_y=0)" |
| 132 |
] |
| 133 |
}, |
| 134 |
{ |
| 135 |
"cell_type": "code", |
| 136 |
"execution_count": null, |
| 137 |
"metadata": {}, |
| 138 |
"outputs": [], |
| 139 |
"source": [ |
| 140 |
"# count is the number of elements in each interval\n", |
| 141 |
"hist.count" |
| 142 |
] |
| 143 |
}, |
| 144 |
{ |
| 145 |
"cell_type": "code", |
| 146 |
"execution_count": null, |
| 147 |
"metadata": {}, |
| 148 |
"outputs": [], |
| 149 |
"source": [ |
| 150 |
"# mid points are the mid points of each interval\n", |
| 151 |
"hist.midpoints" |
| 152 |
] |
| 153 |
} |
| 154 |
], |
| 155 |
"metadata": { |
| 156 |
"kernelspec": { |
| 157 |
"display_name": "Python 3", |
| 158 |
"language": "python", |
| 159 |
"name": "python3" |
| 160 |
}, |
| 161 |
"language_info": { |
| 162 |
"codemirror_mode": { |
| 163 |
"name": "ipython", |
| 164 |
"version": 3 |
| 165 |
}, |
| 166 |
"file_extension": ".py", |
| 167 |
"mimetype": "text/x-python", |
| 168 |
"name": "python", |
| 169 |
"nbconvert_exporter": "python", |
| 170 |
"pygments_lexer": "ipython3", |
| 171 |
"version": "3.7.6" |
| 172 |
} |
| 173 |
}, |
| 174 |
"nbformat": 4, |
| 175 |
"nbformat_minor": 1 |
| 176 |
} |