{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Mouse Cursor\n\nThis example sets an alternative cursor on a figure canvas.\n\nNote, this is an interactive example, and must be run to see the effect.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n\nfrom matplotlib.backend_tools import Cursors\n\nfig, axs = plt.subplots(len(Cursors), figsize=(6, len(Cursors) + 0.5),\n gridspec_kw={'hspace': 0})\nfig.suptitle('Hover over an Axes to see alternate Cursors')\n\nfor cursor, ax in zip(Cursors, axs):\n ax.cursor_to_use = cursor\n ax.text(0.5, 0.5, cursor.name,\n horizontalalignment='center', verticalalignment='center')\n ax.set(xticks=[], yticks=[])\n\n\ndef hover(event):\n if fig.canvas.widgetlock.locked():\n # Don't do anything if the zoom/pan tools have been enabled.\n return\n\n fig.canvas.set_cursor(\n event.inaxes.cursor_to_use if event.inaxes else Cursors.POINTER)\n\n\nfig.canvas.mpl_connect('motion_notify_event', hover)\n\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `matplotlib.backend_bases.FigureCanvasBase.set_cursor`\n\n" ] } ], "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.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }