{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Some examples of seaborn-based plots rendered by Bokeh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import seaborn as sns\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": [
    "from scipy import optimize\n",
    "\n",
    "# Set the palette colors.\n",
    "sns.set(palette=\"Set2\")\n",
    "\n",
    "\n",
    "# Build the sin wave\n",
    "def sine_wave(n_x, obs_err_sd=1.5, tp_err_sd=.3):\n",
    "    x = np.linspace(0, (n_x - 1) / 2, n_x)\n",
    "    y = np.sin(x) + np.random.normal(0, obs_err_sd) + np.random.normal(0, tp_err_sd, n_x)\n",
    "    return y\n",
    "\n",
    "sines = np.array([sine_wave(31) for _ in range(20)])\n",
    "\n",
    "# Generate the Seaborn plot with \"ci\" bars.\n",
    "ax = sns.tsplot(sines, err_style=\"ci_bars\", interpolate=False)\n",
    "xmin, xmax = ax.get_xlim()\n",
    "x = np.linspace(xmin, xmax, sines.shape[1])\n",
    "out, _ = optimize.leastsq(lambda p: sines.mean(0) - (np.sin(x / p[1]) + p[0]), (0, 2))\n",
    "a, b = out\n",
    "xx = np.linspace(xmin, xmax, 100)\n",
    "plt.plot(xx, np.sin(xx / b) + a, c=\"#444444\")\n",
    "\n",
    "plt.title(\"Seaborn tsplot with CI in bokeh.\")\n",
    "\n",
    "show(mpl.to_bokeh(notebook=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib as mplc\n",
    "\n",
    "# Generate the pandas dataframe\n",
    "data = np.random.multivariate_normal([0, 0], [[1, 2], [2, 20]], size=100)\n",
    "data = pd.DataFrame(data, columns=[\"X\", \"Y\"])\n",
    "mplc.rc(\"figure\", figsize=(6, 6))\n",
    "\n",
    "# Just plot seaborn kde\n",
    "sns.kdeplot(data, cmap=\"BuGn_d\")\n",
    "\n",
    "plt.title(\"Seaborn kdeplot in bokeh.\")\n",
    "\n",
    "show(mpl.to_bokeh(notebook=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# We generated random data\n",
    "data = 1 + np.random.randn(20, 6)\n",
    "\n",
    "# And then just call the violinplot from Seaborn\n",
    "sns.violinplot(data, color=\"Set3\")\n",
    "\n",
    "plt.title(\"Seaborn violin plot 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
}