{ "cells": [ { "cell_type": "markdown", "id": "eeef6f0b-7e42-4193-9b89-721fd3f06ac5", "metadata": {}, "source": [ "From https://towardsdatascience.com/tooltips-with-pythons-matplotlib-dcd8db758846" ] }, { "cell_type": "code", "execution_count": null, "id": "233af177-7175-4e2c-a486-f3aebf7940fe", "metadata": {}, "outputs": [], "source": [ "%matplotlib widget" ] }, { "cell_type": "code", "execution_count": null, "id": "635c8457-cba9-4e20-b225-aa9e9d7afb1a", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import mplcursors\n", "import seaborn as sns\n", "tips = sns.load_dataset(\"tips\")\n", "\n", "fig, ax = plt.subplots()\n", "sns.scatterplot(data=tips, x=\"total_bill\", y=\"tip\", hue=\"smoker\")\n", "\n", "@mplcursors.cursor(ax, hover=True).connect(\"add\")\n", "def on_add(sel):\n", " sel.annotation.set(text=tips.sex[sel.target.index])\n", " \n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "b101c777-00ea-41f5-a76c-ff69973cd276", "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.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }