| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "code", |
| 5 |
"execution_count": null, |
| 6 |
"id": "choice-grave", |
| 7 |
"metadata": {}, |
| 8 |
"outputs": [], |
| 9 |
"source": [ |
| 10 |
"from bqplot import *\n", |
| 11 |
"\n", |
| 12 |
"import numpy as np\n", |
| 13 |
"import pandas as pd\n", |
| 14 |
"\n", |
| 15 |
"np.random.seed(0)\n", |
| 16 |
"\n", |
| 17 |
"x = np.arange(10)\n", |
| 18 |
"y = np.cumsum(np.random.randn(3, 10), axis=1)\n", |
| 19 |
"\n", |
| 20 |
"x_ord = OrdinalScale(domain=list(range(15)))\n", |
| 21 |
"y_sc = LinearScale()\n", |
| 22 |
"\n", |
| 23 |
"ax_x = Axis(scale=x_ord, set_ticks=True, grid_lines='none')\n", |
| 24 |
"ax_y = Axis(scale=y_sc, grid_lines='none', orientation='vertical')\n", |
| 25 |
"\n", |
| 26 |
"bar = Bars(\n", |
| 27 |
" x=x, y=y,\n", |
| 28 |
" colors=['hotpink', 'orange', 'green'],\n", |
| 29 |
" labels=['One', 'Two', 'Three'],\n", |
| 30 |
" display_legend=True,\n", |
| 31 |
" scales={'x': x_ord, 'y': y_sc}\n", |
| 32 |
")\n", |
| 33 |
"fig = Figure(marks=[bar], axes=[ax_x, ax_y], padding_x=0.025, padding_y=0.025)\n", |
| 34 |
"fig" |
| 35 |
] |
| 36 |
}, |
| 37 |
{ |
| 38 |
"cell_type": "code", |
| 39 |
"execution_count": null, |
| 40 |
"id": "2d1ffd4f", |
| 41 |
"metadata": {}, |
| 42 |
"outputs": [], |
| 43 |
"source": [ |
| 44 |
"bar.colors = ['lightblue', 'lightgreen', 'orange']" |
| 45 |
] |
| 46 |
}, |
| 47 |
{ |
| 48 |
"cell_type": "code", |
| 49 |
"execution_count": null, |
| 50 |
"id": "47ebb15e", |
| 51 |
"metadata": {}, |
| 52 |
"outputs": [], |
| 53 |
"source": [ |
| 54 |
"bar.labels = ['type1', 'type2', 'type3']" |
| 55 |
] |
| 56 |
}, |
| 57 |
{ |
| 58 |
"cell_type": "code", |
| 59 |
"execution_count": null, |
| 60 |
"id": "invisible-hurricane", |
| 61 |
"metadata": {}, |
| 62 |
"outputs": [], |
| 63 |
"source": [ |
| 64 |
"bar.y = - bar.y" |
| 65 |
] |
| 66 |
}, |
| 67 |
{ |
| 68 |
"cell_type": "code", |
| 69 |
"execution_count": null, |
| 70 |
"id": "waiting-florence", |
| 71 |
"metadata": {}, |
| 72 |
"outputs": [], |
| 73 |
"source": [ |
| 74 |
"bar.stroke = 'white'" |
| 75 |
] |
| 76 |
}, |
| 77 |
{ |
| 78 |
"cell_type": "code", |
| 79 |
"execution_count": null, |
| 80 |
"id": "clean-fiber", |
| 81 |
"metadata": {}, |
| 82 |
"outputs": [], |
| 83 |
"source": [ |
| 84 |
"bar.stroke_width = 2" |
| 85 |
] |
| 86 |
}, |
| 87 |
{ |
| 88 |
"cell_type": "code", |
| 89 |
"execution_count": null, |
| 90 |
"id": "clear-england", |
| 91 |
"metadata": {}, |
| 92 |
"outputs": [], |
| 93 |
"source": [ |
| 94 |
"bar.selected_style = dict(fill='green')\n", |
| 95 |
"bar.unselected_style = dict(fill='red')\n", |
| 96 |
"bar.selected = list(range(4, 6))" |
| 97 |
] |
| 98 |
}, |
| 99 |
{ |
| 100 |
"cell_type": "code", |
| 101 |
"execution_count": null, |
| 102 |
"id": "starting-prevention", |
| 103 |
"metadata": {}, |
| 104 |
"outputs": [], |
| 105 |
"source": [ |
| 106 |
"bar.selected = None" |
| 107 |
] |
| 108 |
} |
| 109 |
], |
| 110 |
"metadata": { |
| 111 |
"kernelspec": { |
| 112 |
"display_name": "Python 3 (ipykernel)", |
| 113 |
"language": "python", |
| 114 |
"name": "python3" |
| 115 |
}, |
| 116 |
"language_info": { |
| 117 |
"codemirror_mode": { |
| 118 |
"name": "ipython", |
| 119 |
"version": 3 |
| 120 |
}, |
| 121 |
"file_extension": ".py", |
| 122 |
"mimetype": "text/x-python", |
| 123 |
"name": "python", |
| 124 |
"nbconvert_exporter": "python", |
| 125 |
"pygments_lexer": "ipython3", |
| 126 |
"version": "3.10.0" |
| 127 |
} |
| 128 |
}, |
| 129 |
"nbformat": 4, |
| 130 |
"nbformat_minor": 5 |
| 131 |
} |