Debian Codegraph @

bqplot/ui-tests/tests/notebooks/scatter_update.ipynb

raw
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": null,
6 "id": "considered-injection",
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 "# Test data\n",
16 "\n",
17 "np.random.seed(0)\n",
18 "price_data = pd.DataFrame(np.cumsum(np.random.randn(150, 2).dot([[1.0, -0.8], [-0.8, 1.0]]), axis=0) + 100,\n",
19 " columns=['Security 1', 'Security 2'], index=pd.date_range(start='01-01-2007', periods=150))\n",
20 "size = 100\n",
21 "x_data = range(size)\n",
22 "y_data = np.cumsum(np.random.randn(size) * 100.0)\n",
23 "ord_keys = np.array(['A', 'B', 'C', 'D', 'E', 'F'])\n",
24 "ordinal_data = np.random.randint(5, size=size)\n",
25 "\n",
26 "symbols = ['Security 1', 'Security 2']\n",
27 "\n",
28 "dates_all = price_data.index.values\n",
29 "dates_all_t = dates_all[1:]\n",
30 "sec1_levels = np.array(price_data[symbols[0]].values.flatten())\n",
31 "log_sec1 = np.log(sec1_levels)\n",
32 "sec1_returns = log_sec1[1:] - log_sec1[:-1]\n",
33 "\n",
34 "sec2_levels = np.array(price_data[symbols[1]].values.flatten())\n",
35 "\n",
36 "# First draw\n",
37 "\n",
38 "sc_x = DateScale()\n",
39 "sc_y = LinearScale()\n",
40 "\n",
41 "scatt = Scatter(x=dates_all, y=sec2_levels, scales={'x': sc_x, 'y': sc_y})\n",
42 "ax_x = Axis(scale=sc_x, label='Date')\n",
43 "ax_y = Axis(scale=sc_y, orientation='vertical', tick_format='0.0f', label='Security 2')\n",
44 "\n",
45 "fig = Figure(marks=[scatt], axes=[ax_x, ax_y])\n",
46 "fig"
47 ]
48 },
49 {
50 "cell_type": "code",
51 "execution_count": null,
52 "id": "resistant-attachment",
53 "metadata": {},
54 "outputs": [],
55 "source": [
56 "scatt.opacities = [0.3, 0.5, 1.]"
57 ]
58 },
59 {
60 "cell_type": "code",
61 "execution_count": null,
62 "id": "korean-survivor",
63 "metadata": {},
64 "outputs": [],
65 "source": [
66 "scatt.colors = ['green', 'red', 'blue']"
67 ]
68 },
69 {
70 "cell_type": "code",
71 "execution_count": null,
72 "id": "amazing-belarus",
73 "metadata": {},
74 "outputs": [],
75 "source": [
76 "scatt.y = -scatt.y"
77 ]
78 },
79 {
80 "cell_type": "code",
81 "execution_count": null,
82 "id": "optional-addiction",
83 "metadata": {},
84 "outputs": [],
85 "source": [
86 "scatt.default_size = 70"
87 ]
88 },
89 {
90 "cell_type": "code",
91 "execution_count": null,
92 "id": "chemical-running",
93 "metadata": {},
94 "outputs": [],
95 "source": [
96 "scatt.scales = dict(x=sc_x, y=sc_y, color=ColorScale())\n",
97 "scatt.color = scatt.y"
98 ]
99 },
100 {
101 "cell_type": "code",
102 "execution_count": null,
103 "id": "related-lesbian",
104 "metadata": {},
105 "outputs": [],
106 "source": [
107 "scatt.marker = 'square'"
108 ]
109 },
110 {
111 "cell_type": "code",
112 "execution_count": null,
113 "id": "amazing-owner",
114 "metadata": {},
115 "outputs": [],
116 "source": [
117 "scatt.stroke = 'black'"
118 ]
119 },
120 {
121 "cell_type": "code",
122 "execution_count": null,
123 "id": "going-cylinder",
124 "metadata": {},
125 "outputs": [],
126 "source": [
127 "scatt.stroke = None"
128 ]
129 },
130 {
131 "cell_type": "code",
132 "execution_count": null,
133 "id": "weird-surgeon",
134 "metadata": {},
135 "outputs": [],
136 "source": [
137 "scatt.fill = False"
138 ]
139 },
140 {
141 "cell_type": "code",
142 "execution_count": null,
143 "id": "equivalent-mining",
144 "metadata": {},
145 "outputs": [],
146 "source": [
147 "scatt.selected_style = dict(fill='green')\n",
148 "scatt.unselected_style = dict(fill='red')\n",
149 "scatt.selected = list(range(50, 60))"
150 ]
151 },
152 {
153 "cell_type": "code",
154 "execution_count": null,
155 "id": "angry-consciousness",
156 "metadata": {},
157 "outputs": [],
158 "source": [
159 "scatt.selected = None"
160 ]
161 }
162 ],
163 "metadata": {
164 "kernelspec": {
165 "display_name": "Python 3",
166 "language": "python",
167 "name": "python3"
168 },
169 "language_info": {
170 "codemirror_mode": {
171 "name": "ipython",
172 "version": 3
173 },
174 "file_extension": ".py",
175 "mimetype": "text/x-python",
176 "name": "python",
177 "nbconvert_exporter": "python",
178 "pygments_lexer": "ipython3",
179 "version": "3.9.2"
180 }
181 },
182 "nbformat": 4,
183 "nbformat_minor": 5
184 }