{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Heatmap Slicer" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib widget\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "from mpl_interactions import heatmap_slicer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Comparing heatmaps\n", "\n", "Sometimes I find myself wanting to compare horizontal or vertical slices across two different heatmaps with the same shape. The function `heatmap_slicer` makes this easy and should work for any number of heatmaps from 1 to many (likely not all the way $\\inf$ though). \n", "\n", "The most important options to play with are `slices = {'both', 'vertical', 'horizontal'}`, and `interaction_type = {'move', 'click'}`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "gif": "tight-layout-heatmap-slicer.gif" }, "outputs": [], "source": [ "x = np.linspace(0, np.pi, 100)\n", "y = np.linspace(0, 10, 200)\n", "X, Y = np.meshgrid(x, y)\n", "data1 = np.sin(X) + np.exp(np.cos(Y))\n", "data2 = np.cos(X) + np.exp(np.sin(Y))\n", "fig, axes = heatmap_slicer(\n", " x,\n", " y,\n", " (data1, data2),\n", " slices=\"both\",\n", " heatmap_names=(\"dataset 1\", \"dataset 2\"),\n", " labels=(\"Some wild X variable\", \"Y axis\"),\n", " interaction_type=\"move\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.8" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "01089f0a61ca4214a29a59abc12db8fa": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "071f5fd284394aaabb5a82ac42498a9a": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "1188013ad1af4b24b84c8ec65ecedc5b": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.1", "model_name": "ToolbarModel", "state": { "layout": "IPY_MODEL_721f8ce8b65e4f5888a696a336533c27", "toolitems": [ [ "Home", "Reset original view", "home", "home" ], [ "Back", "Back to previous view", "arrow-left", "back" ], [ "Forward", "Forward to next view", "arrow-right", "forward" ], [ "Pan", "Pan axes with left mouse, zoom with right", "arrows", "pan" ], [ "Zoom", "Zoom to rectangle", "square-o", "zoom" ], [ "Download", "Download plot", "floppy-o", "save_figure" ] ] } }, "13126ef3af3e457db5b8e5e3da6a48ab": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "1347c00042e5454e8a504c94962d8096": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.1", "model_name": "MPLCanvasModel", "state": { "_figure_label": "Figure 4", "_height": 899, "_width": 1799, "layout": "IPY_MODEL_ef3945e12d304cf39a9b5245d3f073f7", "toolbar": "IPY_MODEL_acf3277ecc38448499fbd710ea1ab4d9", "toolbar_position": "left" } }, "204dbbb0a02f4761b2ac63effe848d5c": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "2db56d505e9c4c8a860a8a4d0f22837e": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.1", "model_name": "MPLCanvasModel", "state": { "_cursor": "default", "_figure_label": "Figure 2", "_height": 899, "_image_mode": "diff", "_message": "zoom rect", "_rubberband_x": -1, "_rubberband_y": 900, "_width": 1799, "layout": "IPY_MODEL_4bef0958f5094b2ea624e1c93133e5c5", "toolbar": "IPY_MODEL_e8a035657ae44c6d91c8c52daae8ebca", "toolbar_position": "left" } }, "4a38a7c5e9ee47a1a685e0ca3621efe6": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.1", "model_name": "ToolbarModel", "state": { "layout": "IPY_MODEL_b2ac2d4e908c4920b9d4895c0c68d30c", "toolitems": [ [ "Home", "Reset original view", "home", "home" ], [ "Back", "Back to previous view", "arrow-left", "back" ], [ "Forward", "Forward to next view", "arrow-right", "forward" ], [ "Pan", "Pan axes with left mouse, zoom with right", "arrows", "pan" ], [ "Zoom", "Zoom to rectangle", "square-o", "zoom" ], [ "Download", "Download plot", "floppy-o", "save_figure" ] ] } }, "4bef0958f5094b2ea624e1c93133e5c5": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "4c42a8bd630e46caba9ef47b8d301f97": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.1", "model_name": "MPLCanvasModel", "state": { "_figure_label": "Figure 3", "_height": 899, "_image_mode": "diff", "_width": 1799, "layout": "IPY_MODEL_01089f0a61ca4214a29a59abc12db8fa", "toolbar": "IPY_MODEL_b3b0baf798764165bb8ef5cd6b2e7293", "toolbar_position": "left" } }, "6ae28a8ad7354377b25eb81853c822ea": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.1", "model_name": "MPLCanvasModel", "state": { "_figure_label": "Figure 5", "_height": 899, "_image_mode": "diff", "_width": 1799, "layout": "IPY_MODEL_7b95b5427fcf4ea1b5e1287b6efa1038", "toolbar": "IPY_MODEL_1188013ad1af4b24b84c8ec65ecedc5b", "toolbar_position": "left" } }, "721f8ce8b65e4f5888a696a336533c27": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "7b95b5427fcf4ea1b5e1287b6efa1038": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "acf3277ecc38448499fbd710ea1ab4d9": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.1", "model_name": "ToolbarModel", "state": { "layout": "IPY_MODEL_204dbbb0a02f4761b2ac63effe848d5c", "toolitems": [ [ "Home", "Reset original view", "home", "home" ], [ "Back", "Back to previous view", "arrow-left", "back" ], [ "Forward", "Forward to next view", "arrow-right", "forward" ], [ "Pan", "Pan axes with left mouse, zoom with right", "arrows", "pan" ], [ "Zoom", "Zoom to rectangle", "square-o", "zoom" ], [ "Download", "Download plot", "floppy-o", "save_figure" ] ] } }, "b2ac2d4e908c4920b9d4895c0c68d30c": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "b36e1d0241314f948d674d2a620b9d00": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "b3b0baf798764165bb8ef5cd6b2e7293": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.1", "model_name": "ToolbarModel", "state": { "layout": "IPY_MODEL_071f5fd284394aaabb5a82ac42498a9a", "toolitems": [ [ "Home", "Reset original view", "home", "home" ], [ "Back", "Back to previous view", "arrow-left", "back" ], [ "Forward", "Forward to next view", "arrow-right", "forward" ], [ "Pan", "Pan axes with left mouse, zoom with right", "arrows", "pan" ], [ "Zoom", "Zoom to rectangle", "square-o", "zoom" ], [ "Download", "Download plot", "floppy-o", "save_figure" ] ] } }, "bdec589a3dd9441786c7a7cef6fa351e": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.1", "model_name": "MPLCanvasModel", "state": { "_figure_label": "Figure 1", "_height": 899, "_image_mode": "diff", "_width": 1799, "layout": "IPY_MODEL_13126ef3af3e457db5b8e5e3da6a48ab", "toolbar": "IPY_MODEL_4a38a7c5e9ee47a1a685e0ca3621efe6", "toolbar_position": "left" } }, "e8a035657ae44c6d91c8c52daae8ebca": { "model_module": "jupyter-matplotlib", "model_module_version": "^0.7.1", "model_name": "ToolbarModel", "state": { "_current_action": "zoom", "layout": "IPY_MODEL_b36e1d0241314f948d674d2a620b9d00", "toolitems": [ [ "Home", "Reset original view", "home", "home" ], [ "Back", "Back to previous view", "arrow-left", "back" ], [ "Forward", "Forward to next view", "arrow-right", "forward" ], [ "Pan", "Pan axes with left mouse, zoom with right", "arrows", "pan" ], [ "Zoom", "Zoom to rectangle", "square-o", "zoom" ], [ "Download", "Download plot", "floppy-o", "save_figure" ] ] } }, "ef3945e12d304cf39a9b5245d3f073f7": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }