{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Findobj Demo\n\nRecursively find all objects that match some criteria\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nimport matplotlib.text as text\n\na = np.arange(0, 3, .02)\nb = np.arange(0, 3, .02)\nc = np.exp(a)\nd = c[::-1]\n\nfig, ax = plt.subplots()\nplt.plot(a, c, 'k--', a, d, 'k:', a, c + d, 'k')\nplt.legend(('Model length', 'Data length', 'Total message length'),\n loc='upper center', shadow=True)\nplt.ylim([-1, 20])\nplt.grid(False)\nplt.xlabel('Model complexity --->')\nplt.ylabel('Message length --->')\nplt.title('Minimum Message Length')\n\n\n# match on arbitrary function\ndef myfunc(x):\n return hasattr(x, 'set_color') and not hasattr(x, 'set_facecolor')\n\n\nfor o in fig.findobj(myfunc):\n o.set_color('blue')\n\n# match on class instances\nfor o in fig.findobj(text.Text):\n o.set_fontstyle('italic')\n\n\nplt.show()" ] } ], "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 }