{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib as mpl\n",
    "import numpy as np\n",
    "from dautil import plotting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def plot_palette(ax, plotter, pal, i, label, ncol=1):\n",
    "    n = len(pal)\n",
    "    x = np.linspace(0.0, 1.0, n)\n",
    "    y = np.arange(n) + i * n\n",
    "    ax.scatter(x, y, c=x, \n",
    "                cmap=mpl.colors.ListedColormap(list(pal)), \n",
    "                s=200)\n",
    "    plotter.plot(x,y, label=label)\n",
    "    handles, labels = ax.get_legend_handles_labels()\n",
    "    ax.legend(loc='best', ncol=ncol, fontsize=18)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def plot_categorical_palettes(ax):\n",
    "    palettes = ['deep', 'muted', 'pastel', 'bright', 'dark', 'colorblind']\n",
    "    plotter = plotting.CyclePlotter(ax)\n",
    "    ax.set_title('Categorical Palettes')\n",
    "\n",
    "    for i, p in enumerate(palettes):\n",
    "        pal = sns.color_palette(p)\n",
    "        plot_palette(ax, plotter, pal, i, p, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def plot_circular_palettes(ax):\n",
    "    ax.set_title('Circular Palettes')\n",
    "    plotter = plotting.CyclePlotter(ax)\n",
    "\n",
    "    pal = sns.color_palette(\"hls\", 6)\n",
    "    plot_palette(ax, plotter, pal, 0, 'hls')\n",
    "\n",
    "    sns.hls_palette(6, l=.3, s=.8)\n",
    "    plot_palette(ax, plotter, pal, 1, 'hls l=.3 s=.8')\n",
    "\n",
    "    pal = sns.color_palette(\"husl\", 6)\n",
    "    plot_palette(ax, plotter, pal, 2, 'husl')\n",
    "\n",
    "    sns.husl_palette(6, l=.3, s=.8)\n",
    "    plot_palette(ax, plotter, pal, 3, 'husl l=.3 s=.8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def plot_brewer_palettes(ax):\n",
    "    ax.set_title('Brewer Palettes')\n",
    "    plotter = plotting.CyclePlotter(ax)\n",
    "\n",
    "    pal = sns.color_palette(\"Paired\")\n",
    "    plot_palette(ax, plotter, pal, 0, 'Paired')\n",
    "\n",
    "    pal = sns.color_palette(\"Set2\", 6)\n",
    "    plot_palette(ax, plotter, pal, 1, 'Set2')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def plot_sequential_palettes(ax):\n",
    "    ax.set_title('Sequential Palettes')\n",
    "    plotter = plotting.CyclePlotter(ax)\n",
    "\n",
    "    pal = sns.color_palette(\"Blues\")\n",
    "    plot_palette(ax, plotter, pal, 0, 'Blues')\n",
    "\n",
    "    pal = sns.color_palette(\"BuGn_r\")\n",
    "    plot_palette(ax, plotter, pal, 1, 'BuGn_r')\n",
    "\n",
    "    pal = sns.color_palette(\"GnBu_d\")\n",
    "    plot_palette(ax, plotter, pal, 2, 'GnBu_d')\n",
    "\n",
    "    pal = sns.color_palette(\"cubehelix\", 6)\n",
    "    plot_palette(ax, plotter, pal, 3, 'cubehelix')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "fig, axes = plt.subplots(2, 2, figsize=(16, 12))\n",
    "plot_categorical_palettes(axes[0][0])\n",
    "plot_circular_palettes(axes[0][1])\n",
    "plot_brewer_palettes(axes[1][0])\n",
    "plot_sequential_palettes(axes[1][1])\n",
    "plotting.hide_axes(axes)\n",
    "plt.tight_layout()"
   ]
  }
 ],
 "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
}
