| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "code", |
| 5 |
"execution_count": null, |
| 6 |
"id": "78b9cef1-88c5-44c7-8636-f83cad335204", |
| 7 |
"metadata": {}, |
| 8 |
"outputs": [], |
| 9 |
"source": [ |
| 10 |
"# Ordinal Scale with strings\n", |
| 11 |
"import numpy\n", |
| 12 |
"from bqplot import *\n", |
| 13 |
"from ipywidgets import *\n", |
| 14 |
"from bqplot.interacts import *\n", |
| 15 |
"\n", |
| 16 |
"scale_x = DateScale()\n", |
| 17 |
"scale_y = OrdinalScale()\n", |
| 18 |
"x = np.arange('2020-01-01', '2020-04-01', dtype='datetime64[M]')\n", |
| 19 |
"scatter = Scatter(x=x, y=[\"A\",\"B\",\"C\"], scales={'x':scale_x, 'y':scale_y})\n", |
| 20 |
"\n", |
| 21 |
"x_axis = Axis(scale = scale_x)\n", |
| 22 |
"y_axis = Axis(\n", |
| 23 |
" scale = scale_y,\n", |
| 24 |
" orientation=\"vertical\",\n", |
| 25 |
")\n", |
| 26 |
"\n", |
| 27 |
"fig1 = Figure(\n", |
| 28 |
" marks=[scatter], \n", |
| 29 |
" axes=[x_axis, y_axis],\n", |
| 30 |
" interaction=BrushSelector(\n", |
| 31 |
" x_scale=scale_x,\n", |
| 32 |
" y_scale=scale_y,\n", |
| 33 |
" marks=[scatter]\n", |
| 34 |
" ),\n", |
| 35 |
" background_style={'fill':'#eee'}\n", |
| 36 |
")\n", |
| 37 |
"fig1.interaction.selected = numpy.array(\n", |
| 38 |
" [[numpy.datetime64('2020-01-29T07:13:07.500'), \"A\"],\n", |
| 39 |
" [numpy.datetime64('2020-02-04T06:39:22.500'), \"B\"]], dtype=object\n", |
| 40 |
")\n", |
| 41 |
"fig1" |
| 42 |
] |
| 43 |
}, |
| 44 |
{ |
| 45 |
"cell_type": "code", |
| 46 |
"execution_count": null, |
| 47 |
"id": "2ff39e13-a0f3-4a7b-9d28-c37bc4587fe2", |
| 48 |
"metadata": {}, |
| 49 |
"outputs": [], |
| 50 |
"source": [ |
| 51 |
"fig1.interaction.selected_y = [\"A\", \"C\"]\n", |
| 52 |
"fig1" |
| 53 |
] |
| 54 |
}, |
| 55 |
{ |
| 56 |
"cell_type": "code", |
| 57 |
"execution_count": null, |
| 58 |
"id": "601c5c97-f6ee-4919-9cda-4a78f471f00d", |
| 59 |
"metadata": {}, |
| 60 |
"outputs": [], |
| 61 |
"source": [ |
| 62 |
"# Ordinal Scale with integers\n", |
| 63 |
"\n", |
| 64 |
"scale_x = DateScale()\n", |
| 65 |
"scale_y = OrdinalScale()\n", |
| 66 |
"x = np.arange('2020-01-01', '2020-04-01', dtype='datetime64[M]')\n", |
| 67 |
"scatter = Scatter(x=x, y=[1, 3, 2], scales={'x':scale_x, 'y':scale_y})\n", |
| 68 |
"\n", |
| 69 |
"x_axis = Axis(scale = scale_x)\n", |
| 70 |
"y_axis = Axis(\n", |
| 71 |
" scale = scale_y,\n", |
| 72 |
" orientation=\"vertical\",\n", |
| 73 |
")\n", |
| 74 |
"\n", |
| 75 |
"fig2 = Figure(\n", |
| 76 |
" marks=[scatter], \n", |
| 77 |
" axes=[x_axis, y_axis],\n", |
| 78 |
" interaction=BrushSelector(\n", |
| 79 |
" x_scale=scale_x,\n", |
| 80 |
" y_scale=scale_y,\n", |
| 81 |
" marks=[scatter]\n", |
| 82 |
" ),\n", |
| 83 |
" background_style={'fill':'#eee'}\n", |
| 84 |
")\n", |
| 85 |
"fig2.interaction.selected = numpy.array(\n", |
| 86 |
" [[numpy.datetime64('2020-01-29T07:13:07.500'), 1],\n", |
| 87 |
" [numpy.datetime64('2020-02-04T06:39:22.500'), 3]], dtype=object\n", |
| 88 |
")\n", |
| 89 |
"fig2" |
| 90 |
] |
| 91 |
}, |
| 92 |
{ |
| 93 |
"cell_type": "code", |
| 94 |
"execution_count": null, |
| 95 |
"id": "5644388d-ea93-450e-b0f3-a2b37ceef2ca", |
| 96 |
"metadata": {}, |
| 97 |
"outputs": [], |
| 98 |
"source": [ |
| 99 |
"fig2.interaction.selected_y = [1,2]\n", |
| 100 |
"fig2" |
| 101 |
] |
| 102 |
} |
| 103 |
], |
| 104 |
"metadata": { |
| 105 |
"kernelspec": { |
| 106 |
"display_name": "Python 3", |
| 107 |
"language": "python", |
| 108 |
"name": "python3" |
| 109 |
}, |
| 110 |
"language_info": { |
| 111 |
"codemirror_mode": { |
| 112 |
"name": "ipython", |
| 113 |
"version": 3 |
| 114 |
}, |
| 115 |
"file_extension": ".py", |
| 116 |
"mimetype": "text/x-python", |
| 117 |
"name": "python", |
| 118 |
"nbconvert_exporter": "python", |
| 119 |
"pygments_lexer": "ipython3", |
| 120 |
"version": "3.9.4" |
| 121 |
} |
| 122 |
}, |
| 123 |
"nbformat": 4, |
| 124 |
"nbformat_minor": 5 |
| 125 |
} |