Ino de Bruijn mpld3 interactive legend test  over 9 years ago

Commit id: 583ef24e015dd25dc07e05cedd0fcc18d12346d5

deletions | additions      

         

{  "metadata": {  "name": "",  "signature": "sha256:d24273bd2bb2c7f86ce3ffdae651806eb54a4c6191c91abc272572a0d0f9a815"  },  "nbformat": 3,  "nbformat_minor": 0,  "worksheets": [  {  "cells": [  {  "cell_type": "code",  "collapsed": false,  "input": [  "import numpy as np\n",  "import sys\n",  "%matplotlib inline"  ],  "language": "python",  "metadata": {},  "outputs": [],  "prompt_number": 1  },  {  "cell_type": "code",  "collapsed": false,  "input": [  "sys.path.insert(0, '/home/idb/src/mpld3')\n",  "import imp\n",  "imp.load_package('mpld3', '/home/idb/src/mpld3')"  ],  "language": "python",  "metadata": {},  "outputs": [  {  "metadata": {},  "output_type": "pyout",  "prompt_number": 2,  "text": [  ""  ]  }  ],  "prompt_number": 2  },  {  "cell_type": "code",  "collapsed": false,  "input": [  "import mpld3\n",  "reload(mpld3)"  ],  "language": "python",  "metadata": {},  "outputs": [  {  "metadata": {},  "output_type": "pyout",  "prompt_number": 3,  "text": [  ""  ]  }  ],  "prompt_number": 3  },  {  "cell_type": "code",  "collapsed": false,  "input": [  "mpld3.__version__"  ],  "language": "python",  "metadata": {},  "outputs": [  {  "metadata": {},  "output_type": "pyout",  "prompt_number": 4,  "text": [  "'0.3git'"  ]  }  ],  "prompt_number": 4  },  {  "cell_type": "code",  "collapsed": false,  "input": [  "import mpld3\n",  "from mpld3 import plugins\n",  "from mpld3.utils import get_id\n",  "import collections\n",  "import matplotlib as mpl\n",  "import matplotlib.pyplot as plt"  ],  "language": "python",  "metadata": {},  "outputs": [],  "prompt_number": 5  },  {  "cell_type": "code",  "collapsed": false,  "input": [  "print reload(mpld3.plugins)\n",  "print reload(mpld3.utils)\n",  "print reload(mpld3)"  ],  "language": "python",  "metadata": {},  "outputs": [  {  "output_type": "stream",  "stream": "stdout",  "text": [  "\n",  "\n",  "\n"  ]  }  ],  "prompt_number": 9  },  {  "cell_type": "code",  "collapsed": false,  "input": [  "N_paths = 5\n",  "N_steps = 100\n",  "\n",  "x = np.linspace(0, 10, 100)\n",  "y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5)\n",  "y = y.cumsum(1)\n",  "\n",  "fig, ax = plt.subplots()\n",  "labels = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",  "line_collections = ax.plot(x, y.T, lw=4, alpha=0.2)\n",  "interactive_legend = plugins.InteractiveLegendPlugin(line_collections, labels)\n",  "plugins.connect(fig, interactive_legend)\n",  "\n",  "mpld3.display()"  ],  "language": "python",  "metadata": {},  "outputs": [  {  "html": [  "\n",  "\n",  "\n",  "\n",  "
\n",
  ""  ],  "metadata": {},  "output_type": "pyout",  "prompt_number": 10,  "text": [  ""  ]  }  ],  "prompt_number": 10  },  {  "cell_type": "code",  "collapsed": false,  "input": [  "N_paths = 5\n",  "N_steps = 100\n",  "\n",  "x1 = np.linspace(0, 10, 100)\n",  "y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5)\n",  "y1 = y.cumsum(1)\n",  "\n",  "x2 = np.linspace(0, 10, 100)\n",  "y = 0.1 * (np.random.random((N_paths, N_steps)) - 0.5)\n",  "y2 = y.cumsum(1)\n",  "\n",  "fig, ax = plt.subplots()\n",  "labels = [\"a\", \"b\",]\n",  "l1 = ax.plot(x1, y1.T, lw=4, alpha=0.1, c='b', label='a')\n",  "l2 = ax.plot(x2, y2.T, lw=4, alpha=0.2, c='r', label='b')\n",  "\n",  "line_collections = [l1,l2]\n",  "plugins.connect(fig, plugins.InteractiveLegendPlugin(line_collections, labels))\n",  "\n",  "mpld3.display()"  ],  "language": "python",  "metadata": {},  "outputs": [  {  "html": [  "\n",  "\n",  "\n",  "\n",  "
\n",
  ""  ],  "metadata": {},  "output_type": "pyout",  "prompt_number": 8,  "text": [  ""  ]  }  ],  "prompt_number": 8  }  ],  "metadata": {}  }  ]  }