Skip to content

Commit c5ca7e5

Browse files
notebooks
1 parent bbeb895 commit c5ca7e5

File tree

2 files changed

+379
-0
lines changed

2 files changed

+379
-0
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"ExecuteTime": {
8+
"end_time": "2020-06-30T14:44:37.710652Z",
9+
"start_time": "2020-06-30T14:44:36.873479Z"
10+
}
11+
},
12+
"outputs": [],
13+
"source": [
14+
"from bqplot import pyplot as plt\n",
15+
"import ipywidgets as widgets\n",
16+
"import numpy as np"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"metadata": {
23+
"ExecuteTime": {
24+
"end_time": "2020-06-30T14:44:37.783189Z",
25+
"start_time": "2020-06-30T14:44:37.771507Z"
26+
}
27+
},
28+
"outputs": [],
29+
"source": [
30+
"# generate some fake \n",
31+
"n = 2000\n",
32+
"x = np.linspace(0.0, 10.0, n)\n",
33+
"np.random.seed(0)\n",
34+
"y = np.cumsum(np.random.randn(n)*10).astype(int)"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": null,
40+
"metadata": {
41+
"ExecuteTime": {
42+
"end_time": "2020-06-30T14:44:37.916067Z",
43+
"start_time": "2020-06-30T14:44:37.789416Z"
44+
}
45+
},
46+
"outputs": [],
47+
"source": [
48+
"fig_hist = plt.figure( title='Histogram in Voila')\n",
49+
"hist = plt.hist(y, bins=25, colors=['steelblue'])\n",
50+
"fig_hist"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"metadata": {
57+
"ExecuteTime": {
58+
"end_time": "2020-06-30T14:44:39.324769Z",
59+
"start_time": "2020-06-30T14:44:39.302431Z"
60+
}
61+
},
62+
"outputs": [],
63+
"source": [
64+
"hist.bins = 10;"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": null,
70+
"metadata": {
71+
"ExecuteTime": {
72+
"end_time": "2020-06-30T14:44:39.967211Z",
73+
"start_time": "2020-06-30T14:44:39.947076Z"
74+
}
75+
},
76+
"outputs": [],
77+
"source": [
78+
"slider = widgets.IntSlider(min=1, max=100, v_model=30)\n",
79+
"slider"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {
86+
"ExecuteTime": {
87+
"end_time": "2020-06-30T14:44:41.005101Z",
88+
"start_time": "2020-06-30T14:44:40.998667Z"
89+
}
90+
},
91+
"outputs": [],
92+
"source": [
93+
"slider.value = 20;"
94+
]
95+
},
96+
{
97+
"cell_type": "code",
98+
"execution_count": null,
99+
"metadata": {
100+
"ExecuteTime": {
101+
"end_time": "2020-06-30T14:44:41.678387Z",
102+
"start_time": "2020-06-30T14:44:41.667654Z"
103+
}
104+
},
105+
"outputs": [],
106+
"source": [
107+
"widgets.link((hist, 'bins'), (slider, 'value'));"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": null,
113+
"metadata": {
114+
"ExecuteTime": {
115+
"end_time": "2020-06-30T14:44:42.384650Z",
116+
"start_time": "2020-06-30T14:44:42.280810Z"
117+
}
118+
},
119+
"outputs": [],
120+
"source": [
121+
"fig_lines = plt.figure( title='Line Chart')\n",
122+
"lines = plt.plot(x, y)\n",
123+
"fig_lines"
124+
]
125+
},
126+
{
127+
"cell_type": "code",
128+
"execution_count": null,
129+
"metadata": {
130+
"ExecuteTime": {
131+
"end_time": "2020-06-30T14:44:43.494747Z",
132+
"start_time": "2020-06-30T14:44:43.473428Z"
133+
}
134+
},
135+
"outputs": [],
136+
"source": [
137+
"selector = plt.brush_int_selector()\n",
138+
"def update_range(*ignore):\n",
139+
" if selector.selected is not None and len(selector.selected) == 2:\n",
140+
" xmin, xmax = selector.selected\n",
141+
" mask = (x > xmin) & (x < xmax)\n",
142+
" hist.sample = y[mask]\n",
143+
"selector.observe(update_range, 'selected') "
144+
]
145+
},
146+
{
147+
"cell_type": "code",
148+
"execution_count": null,
149+
"metadata": {},
150+
"outputs": [],
151+
"source": []
152+
}
153+
],
154+
"metadata": {
155+
"kernelspec": {
156+
"display_name": "Python 3",
157+
"language": "python",
158+
"name": "python3"
159+
},
160+
"language_info": {
161+
"codemirror_mode": {
162+
"name": "ipython",
163+
"version": 3
164+
},
165+
"file_extension": ".py",
166+
"mimetype": "text/x-python",
167+
"name": "python",
168+
"nbconvert_exporter": "python",
169+
"pygments_lexer": "ipython3",
170+
"version": "3.8.3"
171+
},
172+
"widgets": {
173+
"application/vnd.jupyter.widget-state+json": {
174+
"state": {},
175+
"version_major": 2,
176+
"version_minor": 0
177+
}
178+
}
179+
},
180+
"nbformat": 4,
181+
"nbformat_minor": 4
182+
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"from bqplot import pyplot as plt\n",
10+
"import ipywidgets as widgets\n",
11+
"import numpy as np"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"# generate some fake data\n",
21+
"np.random.seed(0)\n",
22+
"n = 2000\n",
23+
"x = np.linspace(0.0, 10.0, n)\n",
24+
"y = np.cumsum(np.random.randn(n)*10).astype(int)"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"metadata": {},
31+
"outputs": [],
32+
"source": [
33+
"# create a bqplot figure\n",
34+
"fig_hist = plt.figure(title='Histogram')\n",
35+
"hist = plt.hist(y, bins=25, colors=['steelblue'])\n",
36+
"fig_hist"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"# slider = widgets.IntSlider(min=1, max=100, v_model=30)\n",
46+
"# widgets.link((fig_hist, 'bins'), (slider, 'value'))\n",
47+
"# slider\n",
48+
"import ipyvuetify as v\n",
49+
"slider = v.Slider(thumb_label='always', class_=\"px-4\", v_model=30)\n",
50+
"widgets.link((slider, 'v_model'), (hist, 'bins'))\n",
51+
"slider"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": null,
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"fig_lines = plt.figure( title='Line Chart')\n",
61+
"lines = plt.plot(x, y)\n",
62+
"fig_lines"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": null,
68+
"metadata": {},
69+
"outputs": [],
70+
"source": [
71+
"selector = plt.brush_int_selector()\n",
72+
"def update_range(*ignore):\n",
73+
" if selector.selected is not None and len(selector.selected) == 2:\n",
74+
" xmin, xmax = selector.selected\n",
75+
" mask = (x > xmin) & (x < xmax)\n",
76+
" hist.sample = y[mask]\n",
77+
"selector.observe(update_range, 'selected') "
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": null,
83+
"metadata": {},
84+
"outputs": [],
85+
"source": [
86+
"line_styles = ['dashed', 'solid', 'dotted']\n",
87+
"widget_line_styles = v.Select(items=line_styles, label='line style', v_model=line_styles[0])\n",
88+
"widget_line_styles"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": null,
94+
"metadata": {},
95+
"outputs": [],
96+
"source": [
97+
"widgets.link((widget_line_styles, 'v_model'), (lines, 'line_style'));"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"metadata": {},
104+
"outputs": [],
105+
"source": []
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": null,
110+
"metadata": {},
111+
"outputs": [],
112+
"source": [
113+
"v.Layout(pa_4=True, _metadata={'mount_id': 'content-nav'}, column=True, children=[slider, widget_line_styles]);"
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": null,
119+
"metadata": {},
120+
"outputs": [],
121+
"source": [
122+
"fig_hist.layout.width = 'auto'\n",
123+
"fig_hist.layout.height = 'auto'\n",
124+
"fig_hist.layout.min_height = '300px' # so it still shows nicely in the notebook\n",
125+
"\n",
126+
"fig_lines.layout.width = 'auto'\n",
127+
"fig_lines.layout.height = 'auto'\n",
128+
"fig_lines.layout.min_height = '300px' # so it still shows nicely in the notebook\n",
129+
"\n",
130+
"\n",
131+
"content_main = v.Layout(\n",
132+
" _metadata={'mount_id': 'content-main'},\n",
133+
" row=True, wrap=True, align_center=True, children=[\n",
134+
" v.Flex(xs12=True, lg6=True, children=[\n",
135+
" fig_hist\n",
136+
" ]),\n",
137+
" v.Flex(xs12=True, lg6=True, children=[\n",
138+
" fig_lines\n",
139+
" ]),\n",
140+
" ])\n",
141+
"\n",
142+
"# no need to display content_main for the voila-vuetify template\n",
143+
"# but might be useful for debugging\n",
144+
"content_main"
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": null,
150+
"metadata": {},
151+
"outputs": [],
152+
"source": []
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
157+
"metadata": {},
158+
"outputs": [],
159+
"source": []
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": null,
164+
"metadata": {},
165+
"outputs": [],
166+
"source": []
167+
}
168+
],
169+
"metadata": {
170+
"kernelspec": {
171+
"display_name": "Python 3",
172+
"language": "python",
173+
"name": "python3"
174+
},
175+
"language_info": {
176+
"codemirror_mode": {
177+
"name": "ipython",
178+
"version": 3
179+
},
180+
"file_extension": ".py",
181+
"mimetype": "text/x-python",
182+
"name": "python",
183+
"nbconvert_exporter": "python",
184+
"pygments_lexer": "ipython3",
185+
"version": "3.8.3"
186+
},
187+
"widgets": {
188+
"application/vnd.jupyter.widget-state+json": {
189+
"state": {},
190+
"version_major": 2,
191+
"version_minor": 0
192+
}
193+
}
194+
},
195+
"nbformat": 4,
196+
"nbformat_minor": 4
197+
}

0 commit comments

Comments
 (0)