{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Some examples of mpl-based plots rendered by Bokeh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "from bokeh import mpl\n",
    "from bokeh.plotting import output_notebook, show"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "x = np.linspace(-2 * np.pi, 2 * np.pi, 100)\n",
    "y = np.sin(x / 2)\n",
    "z = np.cos(x / 4)\n",
    "\n",
    "plt.title(\"Matplotlib Figure in Bokeh\")\n",
    "plt.plot(x, y, \"r-\", marker='o')\n",
    "plt.plot(x, z, \"g-x\", linestyle=\"-.\")\n",
    "\n",
    "show(mpl.to_bokeh())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from matplotlib.collections import LineCollection\n",
    "from bokeh import mpl\n",
    "\n",
    "# In order to efficiently plot many lines in a single set of axes,\n",
    "# add the lines all at once. Here is a simple example showing how it is done.\n",
    "\n",
    "N = 50\n",
    "x = np.arange(N)\n",
    "# Here are many sets of y to plot vs x\n",
    "ys = [x + i for i in x]\n",
    "\n",
    "colors = ['#ff0000', '#008000', '#0000ff', '#00bfbf', '#bfbf00', '#bf00bf', '#000000']\n",
    "\n",
    "line_segments = LineCollection([list(zip(x, y)) for y in ys], color=colors,\n",
    "                                linewidth=(0.5, 1, 1.5, 2), linestyle='dashed')\n",
    "\n",
    "ax = plt.axes()\n",
    "ax.add_collection(line_segments)\n",
    "ax.set_title('Line Collection with dashed colors')\n",
    "\n",
    "show(mpl.to_bokeh())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from matplotlib.collections import PolyCollection\n",
    "\n",
    "# Generate data. In this case, we'll make a bunch of center-points and generate\n",
    "# verticies by subtracting random offsets from those center-points\n",
    "numpoly, numverts = 100, 4\n",
    "centers = 100 * (np.random.random((numpoly, 2)) - 0.5)\n",
    "offsets = 10 * (np.random.random((numverts, numpoly, 2)) - 0.5)\n",
    "verts = centers + offsets\n",
    "verts = np.swapaxes(verts, 0, 1)\n",
    "\n",
    "# In your case, \"verts\" might be something like:\n",
    "# verts = zip(zip(lon1, lat1), zip(lon2, lat2), ...)\n",
    "# If \"data\" in your case is a numpy array, there are cleaner ways to reorder\n",
    "# things to suit.\n",
    "\n",
    "facecolors = ['red', 'green', 'blue', 'cyan', 'yellow', 'magenta', 'black']\n",
    "\n",
    "edgecolors = ['cyan', 'yellow', 'magenta', 'black', 'red', 'green', 'blue']\n",
    "\n",
    "widths = [5, 10, 20, 10, 5]\n",
    "\n",
    "\n",
    "# Make the collection and add it to the plot.\n",
    "col = PolyCollection(verts, facecolor=facecolors, edgecolor=edgecolors,\n",
    "                     linewidth=widths, linestyle='--', alpha=0.5)\n",
    "\n",
    "ax = plt.axes()\n",
    "ax.add_collection(col)\n",
    "\n",
    "plt.xlim([-60, 60])\n",
    "plt.ylim([-60, 60])\n",
    "\n",
    "plt.title(\"MPL-PolyCollection support in Bokeh\")\n",
    "\n",
    "show(mpl.to_bokeh())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "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.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
