Created
October 20, 2015 19:39
-
-
Save cldougl/91321a0d97b1d8f366b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "# Dendrograms in Python" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'1.8.8'" | |
| ] | |
| }, | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "import plotly\n", | |
| "plotly.__version__" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "##### Simple Example" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\"seamless=\"seamless\" src=\"https://plot.ly/~chelsea_lyn/7679.embed\" height=\"100%\" width=\"100%\"></iframe>" | |
| ], | |
| "text/plain": [ | |
| "<plotly.tools.PlotlyDisplay object>" | |
| ] | |
| }, | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "import numpy as np\n", | |
| " \n", | |
| "import plotly.plotly as py\n", | |
| "from plotly.tools import FigureFactory as FF\n", | |
| "\n", | |
| "X = np.random.rand(5,5)\n", | |
| "dendro = FF.create_dendrogram(X)\n", | |
| "py.iplot(dendro)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\"seamless=\"seamless\" src=\"https://plot.ly/~chelsea_lyn/7685.embed\" height=\"100%\" width=\"100%\"></iframe>" | |
| ], | |
| "text/plain": [ | |
| "<plotly.tools.PlotlyDisplay object>" | |
| ] | |
| }, | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "X = np.random.rand(10,10)\n", | |
| "names = ['Jack', 'Oxana', 'John', 'Chelsea', 'Mark', 'Jack', 'Oxana', 'John', 'Chelsea', 'Mark']\n", | |
| "dendro = FF.create_dendrogram(X, orientation='bottom', labels=names)\n", | |
| "\n", | |
| "py.iplot(dendro, height=1000)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "### Reference" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Help on function create_dendrogram in module plotly.tools:\n", | |
| "\n", | |
| "create_dendrogram(X, orientation='bottom', labels=None, colorscale=None)\n", | |
| " BETA function that returns a dendrogram Plotly figure object.\n", | |
| " \n", | |
| " :param (ndarray) X: Matrix of observations as array of arrays\n", | |
| " :param (str) orientation: 'top', 'right', 'bottom', or 'left'\n", | |
| " :param (list) labels: List of axis category labels(observation labels)\n", | |
| " :param (list) colorscale: Optional colorscale for dendrogram tree\n", | |
| " clusters\n", | |
| " \n", | |
| " Example 1: Simple bottom oriented dendrogram\n", | |
| " ```\n", | |
| " import numpy as np\n", | |
| " \n", | |
| " import plotly.plotly as py\n", | |
| " from plotly.tools import FigureFactory as FF\n", | |
| " \n", | |
| " X = np.random.rand(5,5)\n", | |
| " dendro = FF.create_dendrogram(X)\n", | |
| " py.iplot(dendro, validate=False, height=300, width=1000)\n", | |
| " \n", | |
| " ```\n", | |
| " \n", | |
| " Example 2: Dendrogram to put on the left of the heatmap\n", | |
| " ```\n", | |
| " X = np.random.rand(5,5)\n", | |
| " names = ['Jack', 'Oxana', 'John', 'Chelsea', 'Mark']\n", | |
| " dendro = FF.create_dendrogram(X, orientation='right', labels=names)\n", | |
| " \n", | |
| " py.iplot(dendro, validate=False, height=1000, width=300)\n", | |
| " ```\n", | |
| "\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "help(FF.create_dendrogram)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "from IPython.display import display, HTML\n", | |
| "\n", | |
| "display(HTML('<link href=\"//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700\" rel=\"stylesheet\" type=\"text/css\" />'))\n", | |
| "display(HTML('<link rel=\"stylesheet\" type=\"text/css\" href=\"http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css\">'))\n", | |
| "\n", | |
| "! pip install publisher --upgrade\n", | |
| "import publisher\n", | |
| "publisher.publish(\n", | |
| " 'candlestick-charts.ipynb', 'python/candlestick-charts', 'Candlestick Charts',\n", | |
| " 'How to make interactive candlestick charts in Python with Plotly. '\n", | |
| " 'Six examples of candlestick charts with Pandas, time series, and yahoo finance data.',\n", | |
| " title = 'Python Candlestick Charts | plotly',\n", | |
| " thumbnail='/images/candlestick.png', language='python',\n", | |
| " page_type='example_index', has_thumbnail='true', display_as='chart_type', order=28)" | |
| ] | |
| } | |
| ], | |
| "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.2" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment