{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "78b9cef1-88c5-44c7-8636-f83cad335204", "metadata": {}, "outputs": [], "source": [ "# Ordinal Scale with strings\n", "import numpy\n", "from bqplot import *\n", "from ipywidgets import *\n", "from bqplot.interacts import *\n", "\n", "scale_x = DateScale()\n", "scale_y = OrdinalScale()\n", "x = np.arange('2020-01-01', '2020-04-01', dtype='datetime64[M]')\n", "scatter = Scatter(x=x, y=[\"A\",\"B\",\"C\"], scales={'x':scale_x, 'y':scale_y})\n", "\n", "x_axis = Axis(scale = scale_x)\n", "y_axis = Axis(\n", " scale = scale_y,\n", " orientation=\"vertical\",\n", ")\n", "\n", "fig1 = Figure(\n", " marks=[scatter], \n", " axes=[x_axis, y_axis],\n", " interaction=BrushSelector(\n", " x_scale=scale_x,\n", " y_scale=scale_y,\n", " marks=[scatter]\n", " ),\n", " background_style={'fill':'#eee'}\n", ")\n", "fig1.interaction.selected = numpy.array(\n", " [[numpy.datetime64('2020-01-29T07:13:07.500'), \"A\"],\n", " [numpy.datetime64('2020-02-04T06:39:22.500'), \"B\"]], dtype=object\n", ")\n", "fig1" ] }, { "cell_type": "code", "execution_count": null, "id": "2ff39e13-a0f3-4a7b-9d28-c37bc4587fe2", "metadata": {}, "outputs": [], "source": [ "fig1.interaction.selected_y = [\"A\", \"C\"]\n", "fig1" ] }, { "cell_type": "code", "execution_count": null, "id": "601c5c97-f6ee-4919-9cda-4a78f471f00d", "metadata": {}, "outputs": [], "source": [ "# Ordinal Scale with integers\n", "\n", "scale_x = DateScale()\n", "scale_y = OrdinalScale()\n", "x = np.arange('2020-01-01', '2020-04-01', dtype='datetime64[M]')\n", "scatter = Scatter(x=x, y=[1, 3, 2], scales={'x':scale_x, 'y':scale_y})\n", "\n", "x_axis = Axis(scale = scale_x)\n", "y_axis = Axis(\n", " scale = scale_y,\n", " orientation=\"vertical\",\n", ")\n", "\n", "fig2 = Figure(\n", " marks=[scatter], \n", " axes=[x_axis, y_axis],\n", " interaction=BrushSelector(\n", " x_scale=scale_x,\n", " y_scale=scale_y,\n", " marks=[scatter]\n", " ),\n", " background_style={'fill':'#eee'}\n", ")\n", "fig2.interaction.selected = numpy.array(\n", " [[numpy.datetime64('2020-01-29T07:13:07.500'), 1],\n", " [numpy.datetime64('2020-02-04T06:39:22.500'), 3]], dtype=object\n", ")\n", "fig2" ] }, { "cell_type": "code", "execution_count": null, "id": "5644388d-ea93-450e-b0f3-a2b37ceef2ca", "metadata": {}, "outputs": [], "source": [ "fig2.interaction.selected_y = [1,2]\n", "fig2" ] } ], "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.9.4" } }, "nbformat": 4, "nbformat_minor": 5 }