{
 "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 numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from bokeh import mpl\n",
    "from bokeh.plotting import show"
   ]
  },
  {
   "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",
    "\n",
    "plt.plot(x, y, \"r-\", marker='o')\n",
    "\n",
    "plt.plot(x, z, \"g-x\", linestyle=\"-.\")\n",
    "\n",
    "show(mpl.to_bokeh(plt.gcf(), notebook=True))"
   ]
  },
  {
   "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",
    "\n",
    "ax.add_collection(line_segments)\n",
    "ax.set_title('Line Collection with dashed colors')\n",
    "\n",
    "show(mpl.to_bokeh(notebook=True))"
   ]
  },
  {
   "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",
    "ax = plt.axes()\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",
    "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(notebook=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 0
}