{
"metadata": {
"name": "",
"signature": "sha256:f353b3e8539a5aecbad60fb6c134d3a14cbb59a3a1dafc09b6d6182d5a86196e"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##Cufflinks\n",
"\n",
"This library binds the power of [plotly](http://www.plot.ly) with the flexibility of [pandas](http://pandas.pydata.org/) for easy plotting.\n",
"\n",
"This library is available on https://github.com/santosjorge/cufflinks\n",
"\n",
"This tutorial assumes that the plotly user credentials have already been configured as stated on the [getting started](https://plot.ly/python/getting-started/) guide."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import cufflinks as cf"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%reload_ext autoreload\n",
"%autoreload 2"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Line Chart"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.lines().iplot(kind='scatter',xTitle='Dates',yTitle='Returns',title='Cufflinks - Line Chart',\n",
" world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/Jorge/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 3,
"text": [
""
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.lines(3).iplot(kind='scatter',xTitle='Dates',yTitle='Returns',title='Cufflinks - Filled Line Chart',\n",
" colorscale='-blues',fill=True,world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/Jorge/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 4,
"text": [
""
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.lines(1).iplot(kind='scatter',xTitle='Dates',yTitle='Returns',title='Cufflinks - Besfit Line Chart',\n",
" filename='Cufflinks - Bestfit Line Chart',bestfit=True,colors=['blue'],\n",
" bestfit_colors=['pink'],world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/Jorge/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"text": [
""
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Scatter Chart"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.lines(2).iplot(kind='scatter',mode='markers',size=10,symbol='x',colorscale='paired',\n",
" xTitle='Dates',yTitle='EPS Growth',title='Cufflinks - Scatter Chart',\n",
" world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/Jorge/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"text": [
""
]
}
],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Spread Chart"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.lines(2).iplot(kind='spread',xTitle='Dates',yTitle='Return',title='Cufflinks - Spread Chart',\n",
" world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/Jorge/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"text": [
""
]
}
],
"prompt_number": 7
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bar Chart"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.lines(5).resample('M').iplot(kind='bar',xTitle='Dates',yTitle='Return',title='Cufflinks - Bar Chart',\n",
" world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/Jorge/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"text": [
""
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.lines(5).resample('M').iplot(kind='bar',xTitle='Dates',yTitle='Return',title='Cufflinks - Grouped Bar Chart',\n",
" barmode='stack',world_readable=False)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/Jorge/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 9,
"text": [
""
]
}
],
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Box Plot"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.box(6).iplot(kind='box',xTitle='Stocks',yTitle='Returns Distribution',title='Cufflinks - Box Plot',\n",
" world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/Jorge/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 10,
"text": [
""
]
}
],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Historgram"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.histogram(2).iplot(kind='histogram',opacity=.75,title='Cufflinks - Histogram',\n",
" linecolor='white',world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/Jorge/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 11,
"text": [
""
]
}
],
"prompt_number": 11
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##Heatmap Plot"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.heatmap(20,20).iplot(kind='heatmap',colorscale='spectral',title='Cufflinks - Heatmap',\n",
" world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/Jorge/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 12,
"text": [
""
]
}
],
"prompt_number": 12
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##Bubble Chart"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.bubble(prefix='industry').iplot(kind='bubble',x='x',y='y',size='size',categories='categories',text='text',\n",
" xTitle='Returns',yTitle='Analyst Score',title='Cufflinks - Bubble Chart',\n",
" world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/Jorge/anaconda/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 13,
"text": [
""
]
}
],
"prompt_number": 13
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##Scatter 3D"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.scatter3d(2,150).iplot(kind='scatter3d',x='x',y='y',z='z',size=15,categories='categories',text='text',\n",
" title='Cufflinks - Scatter 3D Chart',colors=['blue','pink'],width=0.5,margin=(0,0,0,0),\n",
" world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'numpy.ndarray' object has no attribute 'values'",
"output_type": "pyerr",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m cf.datagen.scatter3d(2,150).iplot(kind='scatter3d',x='x',y='y',z='z',size=15,categories='categories',text='text',\n\u001b[1;32m 2\u001b[0m \u001b[0mtitle\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'Cufflinks - Scatter 3D Chart'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mcolors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'blue'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'pink'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mwidth\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.5\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mmargin\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m world_readable=True)\n\u001b[0m",
"\u001b[0;32m/Users/Jorge/Dropbox/Development/Git/repos/cufflinks/cufflinks/plotlytools.pyc\u001b[0m in \u001b[0;36m_iplot\u001b[0;34m(self, data, layout, filename, world_readable, kind, title, xTitle, yTitle, zTitle, theme, colors, colorscale, fill, width, mode, symbol, size, barmode, sortbars, boxpoints, annotations, keys, bestfit, bestfit_colors, categories, x, y, z, text, gridcolor, zerolinecolor, margin, asFrame, asDates, asFigure, asImage, dimensions, asPlot, asUrl, **kwargs)\u001b[0m\n\u001b[1;32m 514\u001b[0m \t\t\t\t\t\t\t\t\t\t\tline=Line(width=width)),textfont=getLayout(theme=theme)['xaxis']['titlefont'])\n\u001b[1;32m 515\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'3d'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mkind\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 516\u001b[0;31m \t\t\t\t\t_data=Scatter3d(x=_x,y=_y,z=_z.values,mode=mode,name=_,\n\u001b[0m\u001b[1;32m 517\u001b[0m \t\t\t\t\t\t\tmarker=Marker(color=colors[_],symbol=symbol,size=_size,opacity=opacity,\n\u001b[1;32m 518\u001b[0m \t\t\t\t\t\t\t\t\t\t\tline=Line(width=width)),textfont=getLayout(theme=theme)['xaxis']['titlefont'])\n",
"\u001b[0;31mAttributeError\u001b[0m: 'numpy.ndarray' object has no attribute 'values'"
]
}
],
"prompt_number": 14
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##Bubble 3D "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.bubble3d(5,4).iplot(kind='bubble3d',x='x',y='y',z='z',size='size',text='text',categories='categories',\n",
" title='Cufflinks - Bubble 3D Chart',colorscale='set1',\n",
" width=.5,opacity=.8,world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##Surface"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cf.datagen.sinwave(10,.25).iplot(kind='surface',theme='solar',colorscale='brbg',title='Cufflinks - Surface Plot',\n",
" margin=(0,0,0,0),world_readable=True)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}