{ "cells": [ { "cell_type": "markdown", "id": "141c3586-4c3b-4d10-96bc-f7af7195a0dd", "metadata": {}, "source": [ "## bia-bob demo\n", "stackview is compatible with [bia-bob](https://github.com/haesleinhuepf/bia-bob) providing hints to bob how to use it. This might be relevant, e.g. if you aim to generate custom interactive widgets to explore your data." ] }, { "cell_type": "code", "execution_count": 1, "id": "99be5861-af31-4668-8323-7aab4765a5ec", "metadata": {}, "outputs": [], "source": [ "import bia_bob" ] }, { "cell_type": "code", "execution_count": 2, "id": "ed73f92a-09fb-4d71-bef7-63acf0437584", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
speciesislandbill_length_mmbill_depth_mmflipper_length_mmbody_mass_gsex
0AdelieTorgersen39.118.7181.03750.0Male
1AdelieTorgersen39.517.4186.03800.0Female
2AdelieTorgersen40.318.0195.03250.0Female
3AdelieTorgersenNaNNaNNaNNaNNaN
4AdelieTorgersen36.719.3193.03450.0Female
\n", "
" ], "text/plain": [ " species island bill_length_mm bill_depth_mm flipper_length_mm \\\n", "0 Adelie Torgersen 39.1 18.7 181.0 \n", "1 Adelie Torgersen 39.5 17.4 186.0 \n", "2 Adelie Torgersen 40.3 18.0 195.0 \n", "3 Adelie Torgersen NaN NaN NaN \n", "4 Adelie Torgersen 36.7 19.3 193.0 \n", "\n", " body_mass_g sex \n", "0 3750.0 Male \n", "1 3800.0 Female \n", "2 3250.0 Female \n", "3 NaN NaN \n", "4 3450.0 Female " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import seaborn as sns\n", "import pandas as pd\n", "\n", "# Load the penguin dataset\n", "penguins_df = sns.load_dataset('penguins')\n", "\n", "# Display the first few rows of the DataFrame\n", "penguins_df.head()" ] }, { "cell_type": "markdown", "id": "a4f4bad3-2184-4017-b061-a870b878b55d", "metadata": {}, "source": [ "You can ask `%bob` to visualize data for you. In case `stackview` is installed and you mention a use-case for it, it may propose code like this:" ] }, { "cell_type": "code", "execution_count": 3, "id": "93fa311a-7345-4e02-9466-beea1ca3cd68", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " This notebook may contain text, code and images generated by artificial intelligence.\n", " \n", " Used model: claude-3-5-sonnet-20240620,\n", " vision model: gpt-4o-2024-05-13,\n", " endpoint: None,\n", " bia-bob version: 0.19.0.\n", " It is good scientific practice to check the code and results it produces carefully.\n", " \n", " Read more about code generation using bia-bob.\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "I will create two connected scatterplots side-by-side using the penguins_df DataFrame, allowing for interactive selection between the plots.\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%bob display the penguins_df in two connected scatterplots side-by-side." ] }, { "cell_type": "code", "execution_count": 4, "id": "3e2ba589-83e8-43f1-a144-7855d8910579", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "4601b43a9ebb43cebace4733a7280694", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(HBox(children=(VBox(children=(VBox(children=(HBox(children=(Label(value='Axes '), Dropdown(inde…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import ipywidgets as widgets\n", "from ipywidgets import HBox\n", "import stackview\n", "\n", "def update2(e=None):\n", " widget2.update()\n", "\n", "def update1(e=None):\n", " widget1.update()\n", "\n", "widget1 = stackview.scatterplot(df=penguins_df, column_x=\"bill_length_mm\", column_y=\"bill_depth_mm\", selection_changed_callback=update2)\n", "widget2 = stackview.scatterplot(df=penguins_df, column_x=\"flipper_length_mm\", column_y=\"body_mass_g\", selection_changed_callback=update1)\n", "\n", "display(HBox([widget1, widget2])) # Arrange the widgets side by side using HBox" ] }, { "cell_type": "code", "execution_count": null, "id": "1cd91c32-9eea-44f6-a13c-5093b55ccfa1", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 5 }