From b53bf06e2242172e44797caf8ecadac02dbee8d9 Mon Sep 17 00:00:00 2001 From: kushalkolar Date: Wed, 1 May 2024 19:22:48 -0400 Subject: [PATCH] cycle colors in scatter example --- examples/notebooks/quickstart.ipynb | 34 ++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/examples/notebooks/quickstart.ipynb b/examples/notebooks/quickstart.ipynb index 84886ecae..9bfd822ab 100644 --- a/examples/notebooks/quickstart.ipynb +++ b/examples/notebooks/quickstart.ipynb @@ -1422,7 +1422,7 @@ "# use an alpha value since this will be a lot of points\n", "scatter_graphic = subplot_scatter.add_scatter(data=cloud, sizes=3, colors=colors, alpha=0.6)\n", "\n", - "fig_scatter.show()" + "fig_scatter.show(sidecar=True)" ] }, { @@ -1536,12 +1536,40 @@ "outputs": [], "source": [ "def update_points(subplot):\n", + " # move every point by a small amount\n", " deltas = np.random.normal(size=scatter_graphic.data().shape, loc=0, scale=0.15)\n", - " scatter_graphic.data = scatter_graphic.data() + deltas\n", + " scatter_graphic.data = scatter_graphic.data() + deltas \n", "\n", "subplot_scatter.add_animations(update_points)" ] }, + { + "cell_type": "markdown", + "id": "1592c6cd-d10a-4bda-ac4b-e06d428ffa1d", + "metadata": {}, + "source": [ + "Another animation function to cycle the colors of one of the clouds" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fb0394a3-47d9-4620-a754-d04d5f313cc7", + "metadata": {}, + "outputs": [], + "source": [ + "i = 0.05\n", + "def cycle_colors(subplot):\n", + " global i\n", + " # cycle the red values\n", + " scatter_graphic.colors[n_points * 2:, 0] = np.abs(np.sin(i))\n", + " scatter_graphic.colors[n_points * 2:, 1] = np.abs(np.sin(i + (np.pi / 4)))\n", + " scatter_graphic.colors[n_points * 2:, 2] = np.abs(np.cos(i))\n", + " i += 0.05\n", + "\n", + "subplot_scatter.add_animations(cycle_colors)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -2020,7 +2048,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.11.2" } }, "nbformat": 4,