Debian Codegraph @

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

raw
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": null,
6 "id": "af595ff1",
7 "metadata": {},
8 "outputs": [],
9 "source": [
10 "from bqplot import *\n",
11 "import numpy as np\n",
12 "\n",
13 "price_data1 = [['2015-01-02 00:00:00', [161.31, 163.31, 161.0, 162.06]],\n",
14 " ['2015-01-05 00:00:00', [161.27, 161.27, 159.19, 159.51]],\n",
15 " ['2015-01-06 00:00:00', [159.67, 159.96, 155.17, 156.07]],\n",
16 " ['2015-01-07 00:00:00', [157.2, 157.2, 154.03, 155.05]],\n",
17 " ['2015-01-08 00:00:00', [156.24, 159.044, 155.55, 158.42]],\n",
18 " ['2015-01-09 00:00:00', [158.42, 160.34, 157.25, 159.11]],\n",
19 " ['2015-01-12 00:00:00', [159.0, 159.25, 155.76, 156.44]],\n",
20 " ['2015-01-13 00:00:00', [157.26, 159.97, 155.68, 156.81]],\n",
21 " ['2015-01-14 00:00:00', [154.86, 156.49, 153.74, 155.8]],\n",
22 " ['2015-01-15 00:00:00', [156.69, 156.97, 154.16, 154.57]]]\n",
23 "\n",
24 "price_data2 = [['2015-01-02 00:00:00', [111.39, 111.44, 107.35, 109.33]],\n",
25 " ['2015-01-05 00:00:00', [108.29, 108.65, 105.41, 106.25]],\n",
26 " ['2015-01-06 00:00:00', [106.54, 107.43, 104.63, 106.26]],\n",
27 " ['2015-01-07 00:00:00', [107.2, 108.2, 106.695, 107.75]],\n",
28 " ['2015-01-08 00:00:00', [109.23, 112.15, 108.7, 111.89]],\n",
29 " ['2015-01-09 00:00:00', [112.67, 113.25, 110.21, 112.01]],\n",
30 " ['2015-01-12 00:00:00', [112.6, 112.63, 108.8, 109.25]],\n",
31 " ['2015-01-13 00:00:00', [111.43, 112.8, 108.91, 110.22]],\n",
32 " ['2015-01-14 00:00:00', [109.04, 110.49, 108.5, 109.8]],\n",
33 " ['2015-01-15 00:00:00', [110.0, 110.06, 106.66, 106.82]]]\n",
34 "\n",
35 "from bqplot.traits import convert_to_date\n",
36 "\n",
37 "dates1 = convert_to_date([d[0] for d in price_data1])\n",
38 "prices1 = [d[1] for d in price_data1]\n",
39 "\n",
40 "dates2 = convert_to_date([d[0] for d in price_data2])\n",
41 "prices2 = [d[1] for d in price_data2]\n",
42 "\n",
43 "sc_y = LinearScale()\n",
44 "sc_x = LinearScale()\n",
45 "\n",
46 "ax_x = Axis(label='X', scale=sc_x)\n",
47 "ax_y = Axis(label='Y', scale=sc_y, orientation='vertical', tick_format='0.2f')\n",
48 "\n",
49 "ohlc = OHLC(x=np.arange(len(dates2)) + 1, y=np.array(prices2) / 60,\n",
50 " marker='bar', scales={'x': sc_x, 'y': sc_y}, colors=['dodgerblue','orange'])\n",
51 "\n",
52 "Figure(axes=[ax_x, ax_y], marks=[ohlc])"
53 ]
54 },
55 {
56 "cell_type": "code",
57 "execution_count": null,
58 "id": "e65e1273",
59 "metadata": {},
60 "outputs": [],
61 "source": [
62 "ohlc.marker = 'candle'"
63 ]
64 },
65 {
66 "cell_type": "code",
67 "execution_count": null,
68 "id": "a5b90e65",
69 "metadata": {},
70 "outputs": [],
71 "source": [
72 "ohlc.colors = ['green', 'red']"
73 ]
74 },
75 {
76 "cell_type": "code",
77 "execution_count": null,
78 "id": "254b3eb4",
79 "metadata": {},
80 "outputs": [],
81 "source": [
82 "ohlc.opacities = [0.5, 0.5, 0.5, 0.2]"
83 ]
84 },
85 {
86 "cell_type": "code",
87 "execution_count": null,
88 "id": "9c3cfbac",
89 "metadata": {},
90 "outputs": [],
91 "source": [
92 "# Doesn't work?\n",
93 "# ohlc.format = 'hl'"
94 ]
95 },
96 {
97 "cell_type": "code",
98 "execution_count": null,
99 "id": "981636d4",
100 "metadata": {},
101 "outputs": [],
102 "source": [
103 "ohlc.stroke = 'green'"
104 ]
105 },
106 {
107 "cell_type": "code",
108 "execution_count": null,
109 "id": "ab3c0eaa",
110 "metadata": {},
111 "outputs": [],
112 "source": [
113 "ohlc.stroke_width = 3"
114 ]
115 },
116 {
117 "cell_type": "code",
118 "execution_count": null,
119 "id": "3b80b31f",
120 "metadata": {},
121 "outputs": [],
122 "source": [
123 "ohlc.x = - ohlc.x"
124 ]
125 },
126 {
127 "cell_type": "code",
128 "execution_count": null,
129 "id": "50a900b0",
130 "metadata": {},
131 "outputs": [],
132 "source": [
133 "ohlc.y = 2 * ohlc.y"
134 ]
135 },
136 {
137 "cell_type": "code",
138 "execution_count": null,
139 "id": "7f8af7f4",
140 "metadata": {},
141 "outputs": [],
142 "source": [
143 "# Doesn't work?\n",
144 "\n",
145 "# ohlc.selected_style = {'fill': 'blue'}\n",
146 "# ohlc.selected = [0, 2, 5]"
147 ]
148 }
149 ],
150 "metadata": {
151 "kernelspec": {
152 "display_name": "Python 3",
153 "language": "python",
154 "name": "python3"
155 },
156 "language_info": {
157 "codemirror_mode": {
158 "name": "ipython",
159 "version": 3
160 },
161 "file_extension": ".py",
162 "mimetype": "text/x-python",
163 "name": "python",
164 "nbconvert_exporter": "python",
165 "pygments_lexer": "ipython3",
166 "version": "3.9.2"
167 }
168 },
169 "nbformat": 4,
170 "nbformat_minor": 5
171 }