Debian Codegraph @

ui-tests/tests/notebooks/scatter.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"
14 ]
15 },
16 {
17 "cell_type": "code",
18 "execution_count": null,
19 "id": "direct-desperate",
20 "metadata": {},
21 "outputs": [],
22 "source": [
23 "# Test data\n",
24 "\n",
25 "np.random.seed(0)\n",
26 "price_data = pd.DataFrame(np.cumsum(np.random.randn(150, 2).dot([[1.0, -0.8], [-0.8, 1.0]]), axis=0) + 100,\n",
27 " columns=['Security 1', 'Security 2'], index=pd.date_range(start='01-01-2007', periods=150))\n",
28 "size = 100\n",
29 "x_data = range(size)\n",
30 "y_data = np.cumsum(np.random.randn(size) * 100.0)\n",
31 "ord_keys = np.array(['A', 'B', 'C', 'D', 'E', 'F'])\n",
32 "ordinal_data = np.random.randint(5, size=size)\n",
33 "\n",
34 "symbols = ['Security 1', 'Security 2']\n",
35 "\n",
36 "dates_all = price_data.index.values\n",
37 "dates_all_t = dates_all[1:]\n",
38 "sec1_levels = np.array(price_data[symbols[0]].values.flatten())\n",
39 "log_sec1 = np.log(sec1_levels)\n",
40 "sec1_returns = log_sec1[1:] - log_sec1[:-1]\n",
41 "\n",
42 "sec2_levels = np.array(price_data[symbols[1]].values.flatten())"
43 ]
44 },
45 {
46 "cell_type": "code",
47 "execution_count": null,
48 "id": "juvenile-dialogue",
49 "metadata": {},
50 "outputs": [],
51 "source": [
52 "# Create Scatter\n",
53 "sc_x = DateScale()\n",
54 "sc_y = LinearScale()\n",
55 "\n",
56 "scatt = Scatter(x=dates_all, y=sec2_levels, scales={'x': sc_x, 'y': sc_y})\n",
57 "ax_x = Axis(scale=sc_x, label='Date')\n",
58 "ax_y = Axis(scale=sc_y, orientation='vertical', tick_format='0.0f', label='Security 2')\n",
59 "\n",
60 "fig = Figure(marks=[scatt], axes=[ax_x, ax_y])\n",
61 "fig"
62 ]
63 },
64 {
65 "cell_type": "code",
66 "execution_count": null,
67 "id": "resistant-attachment",
68 "metadata": {},
69 "outputs": [],
70 "source": [
71 "# Update Scatter properties\n",
72 "scatt.opacities = [0.3, 0.5, 1.]\n",
73 "scatt.colors = ['green', 'red', 'blue']\n",
74 "fig"
75 ]
76 }
77 ],
78 "metadata": {
79 "kernelspec": {
80 "display_name": "Python 3",
81 "language": "python",
82 "name": "python3"
83 },
84 "language_info": {
85 "codemirror_mode": {
86 "name": "ipython",
87 "version": 3
88 },
89 "file_extension": ".py",
90 "mimetype": "text/x-python",
91 "name": "python",
92 "nbconvert_exporter": "python",
93 "pygments_lexer": "ipython3",
94 "version": "3.9.2"
95 }
96 },
97 "nbformat": 4,
98 "nbformat_minor": 5
99 }