Skip to content

Commit 9a309ef

Browse files
authored
cycle colors in scatter example (#501)
1 parent b79610c commit 9a309ef

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

examples/notebooks/quickstart.ipynb

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@
14221422
"# use an alpha value since this will be a lot of points\n",
14231423
"scatter_graphic = subplot_scatter.add_scatter(data=cloud, sizes=3, colors=colors, alpha=0.6)\n",
14241424
"\n",
1425-
"fig_scatter.show()"
1425+
"fig_scatter.show(sidecar=True)"
14261426
]
14271427
},
14281428
{
@@ -1536,12 +1536,40 @@
15361536
"outputs": [],
15371537
"source": [
15381538
"def update_points(subplot):\n",
1539+
" # move every point by a small amount\n",
15391540
" deltas = np.random.normal(size=scatter_graphic.data().shape, loc=0, scale=0.15)\n",
1540-
" scatter_graphic.data = scatter_graphic.data() + deltas\n",
1541+
" scatter_graphic.data = scatter_graphic.data() + deltas \n",
15411542
"\n",
15421543
"subplot_scatter.add_animations(update_points)"
15431544
]
15441545
},
1546+
{
1547+
"cell_type": "markdown",
1548+
"id": "1592c6cd-d10a-4bda-ac4b-e06d428ffa1d",
1549+
"metadata": {},
1550+
"source": [
1551+
"Another animation function to cycle the colors of one of the clouds"
1552+
]
1553+
},
1554+
{
1555+
"cell_type": "code",
1556+
"execution_count": null,
1557+
"id": "fb0394a3-47d9-4620-a754-d04d5f313cc7",
1558+
"metadata": {},
1559+
"outputs": [],
1560+
"source": [
1561+
"i = 0.05\n",
1562+
"def cycle_colors(subplot):\n",
1563+
" global i\n",
1564+
" # cycle the red values\n",
1565+
" scatter_graphic.colors[n_points * 2:, 0] = np.abs(np.sin(i))\n",
1566+
" scatter_graphic.colors[n_points * 2:, 1] = np.abs(np.sin(i + (np.pi / 4)))\n",
1567+
" scatter_graphic.colors[n_points * 2:, 2] = np.abs(np.cos(i))\n",
1568+
" i += 0.05\n",
1569+
"\n",
1570+
"subplot_scatter.add_animations(cycle_colors)"
1571+
]
1572+
},
15451573
{
15461574
"cell_type": "code",
15471575
"execution_count": null,
@@ -2020,7 +2048,7 @@
20202048
"name": "python",
20212049
"nbconvert_exporter": "python",
20222050
"pygments_lexer": "ipython3",
2023-
"version": "3.11.3"
2051+
"version": "3.11.2"
20242052
}
20252053
},
20262054
"nbformat": 4,

0 commit comments

Comments
 (0)