Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save plotly/7621515 to your computer and use it in GitHub Desktop.
Save plotly/7621515 to your computer and use it in GitHub Desktop.
{
"metadata": {
"name": "Plotly with IPython - Documentation"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": "Plotly and IPython - Documentation and Examples\n===\n\nBackground\n---\nPlotly ([https://plot.ly](https://plot.ly)) is a collaborative data analysis and graphing platform. Plotly's IPython Graphing Library ([https://plot.ly/python](https://plot.ly)) interfaces Plotly's online graphing tools with your IPython notebook environment. Send data to your Plotly account, embed the graphs in your IPython notebook, and share them in your web browser. Style with code or with our online interface; share your work publicly with a url or privately among other Plotly members; access your graphs from anywhere.\nLearn More\n---\n- A talk and a demo: [Using Plotly and IPython for Scientific Computing](https://www.youtube.com/watch?v=zG8FYPFU9n4&feature=youtu.be&a)\n- Plotly Homepage: [https://plot.ly](https://plot.ly)\n- Plotly APIs for [Python](https://plot.ly/python), [Julia](https://plot.ly/julia), [MATLAB] (https://plot.ly/MATLAB), [R](https://plot.ly/R), [Arduino](https://plot.ly/arduino), [Perl](https://plot.ly/perl) and our [REST protocal](https://plot.ly/REST)\n- Let us know what you think: [chris[at]plot[dot]ly]([mailto:chris@plot.ly])\n"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Import and sign up to plotly\n===\nYou can sign up through the API. We'll generate an temporary password and an API key for you. You can reset your password here: [https://plot.ly/accounts/password/reset/](https://plot.ly/accounts/password/reset/) and you can reset your API key here: [https://plot.ly/api](https://plot.ly/api) under \"Installation Instructions\""
},
{
"cell_type": "code",
"collapsed": false,
"input": "import plotly",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": "username = 'xxxxxxx'\nemail = 'xxxxxx@email.com'\n\nres = plotly.signup(username,email)\nprint res",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n"
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": "py = plotly.plotly(res['un'], res['api_key'])",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "50 Box Plots with 1 Line"
},
{
"cell_type": "code",
"collapsed": false,
"input": "from numpy import *\npy.iplot([{'y': random.randn(5), 'type': 'box'} for i in range(50)], layout={'showlegend': False})",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/28/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 48,
"text": "<IPython.core.display.HTML at 0x104cb6510>"
}
],
"prompt_number": 48
},
{
"cell_type": "raw",
"metadata": {},
"source": "That graph is interactive! Click and drag to zoom, shift-click and drag to pan, double-click to autoscale.\n\nIt's also saved in your newly created plotly account. Click \"view in plotly\" to open it up in our online interface which includes a GUI for styling the graph."
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Concentric Annuli"
},
{
"cell_type": "code",
"collapsed": false,
"input": "from numpy import *\n\n# fill several concentric annuli with random points of equal density\n# color with the \"hue, saturation, lightness, alpha\" color code (hsla)\n# by keeping the hue, saturation, and alpha channels constant and marching\n# up the lightness channel\n\n\nt = 0.1 # thickness\nradius = arange(t, 5., t) \ndensity = 30.\ndata = []\n\nfor i in range(len(radius)):\n r = radius[i]\n npoints = density * pi * (r**2 - (r-t)**2)\n rand_radius = t*random.rand(npoints)+r\n rand_angle = random.rand(npoints)*2*pi\n x = rand_radius*cos(rand_angle)\n y = rand_radius*sin(rand_angle)\n color = 'hsla(284, 100%, '+str(10+i*90/len(radius))+'%, 0.88)'\n data.append({'x': x, 'y': y, 'type':'scatter','mode':'markers','marker':{'color':color}})\n\nl={'autosize': False,'width': 550, 'height': 550,\n\t'xaxis' : { \"ticks\": \"\", \"gridcolor\": \"white\", \"zerolinecolor\": \"white\", \"linecolor\": \"rgb(0, 0, 0)\", \"linewidth\": 3 },\n\t'yaxis' : { \"ticks\": \"\", \"gridcolor\": \"white\", \"zerolinecolor\": \"white\", \"linecolor\": \"rgb(0, 0, 0)\", \"linewidth\": 3 },\n\t'plot_bgcolor': 'rgb(229,229,229)', 'showlegend': False, 'hovermode': 'closest'}\n\npy.iplot(data,layout=l)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/27/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 47,
"text": "<IPython.core.display.HTML at 0x104cb4810>"
}
],
"prompt_number": 47
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Simple Line Plots"
},
{
"cell_type": "code",
"collapsed": false,
"input": "x0 = [1,2,3,4]; y0 = [10,15,13,17]\nx1 = [2,3,4,5]; y1 = [16,5,11,9]\npy.iplot(x0, y0, x1, y1)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\nHigh five! You successfuly sent some data to your account on plotly. View your plot in your browser at https://plot.ly/~chriddyp/1 or inside your plot.ly account where it is named 'plot from API (1)'\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/1/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"text": "<IPython.core.display.HTML at 0x1040beed0>"
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": "py.verbose=False",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": "trace0 = {'x': [1,2,3,4], \n 'y': [10,15,13,17],\n 'type': 'scatter', \n 'mode': 'markers'}\n\ntrace1 = {'x': [2,3,4,5], \n 'y': [16,5,11,9],\n 'type': 'scatter', \n 'mode': 'lines'}\n\ntrace2 = {'x': [1,2,3,4], \n 'y': [12,9,15,12],\n 'type': 'scatter', \n 'mode': 'lines+markers'}\n\npy.iplot([trace0, trace1, trace2])",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/2/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 10,
"text": "<IPython.core.display.HTML at 0x102c56f10>"
}
],
"prompt_number": 10
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Fully Styled Line Plot"
},
{
"cell_type": "code",
"collapsed": false,
"input": "x1 = [1,2,3]; y1 = [4,5,6]\nx2 = [1,2,3]; y2 = [2,10,12]\n \n# plotly's data dictionaries\ntrace1 = {'x': x1,\n 'y': y1,\n \"name\":\"Experiment\",\n \"type\":\"scatter\",\n \"line\":{\n \"color\":\"rgb(3,78,123)\", \n \"width\":6,\n \"dash\":\"dot\"\n },\n \"marker\":{\n \"opacity\":1.0,\n \"symbol\":\"square\",\n \"size\":12,\n \"color\":\"rgb(54,144,192)\",\n \"line\":{\n \"width\":3,\n \"color\":\"darkblue\"\n }\n }\n}\n\ntrace2 = {\"x\":x2,\n \"y\":y2,\n \"name\":\"Control\", \n \"type\":\"scatter\",\n \"line\":{\n \"color\":\"purple\",\n \"width\":4,\n \"dash\":\"dashdot\"\n },\n \"marker\":{\n \"opacity\":0.9,\n \"symbol\":\"cross\",\n \"size\":16,\n \"color\":\"fuchsia\",\n \"line\":{\n \"color\":\"\",\n \"width\":0\n },\n }\n}\n\npy.iplot([trace1, trace2])",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/3/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 11,
"text": "<IPython.core.display.HTML at 0x1040d2d50>"
}
],
"prompt_number": 11
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Basic Area Plot"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# basic-area \ntrace0 = {'x': [1,2,3,4], \n 'y': [0, 2, 3, 5],\n 'fill': 'tozeroy'}\n\ntrace1 = {'x': [1,2,3,4], \n 'y': [3,5,1,7],\n 'fill': 'tonexty'}\n\npy.iplot([trace0, trace1])",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/4/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 13,
"text": "<IPython.core.display.HTML at 0x1040d52d0>"
}
],
"prompt_number": 13
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Bar Charts"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# basic-bar \nx0 = ['giraffes', 'orangutans', 'monkeys'];\ny0 = [20, 14, 23];\ndata = {'x': x0, 'y': y0,\n 'type': 'bar'}\npy.iplot([data])",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/5/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 14,
"text": "<IPython.core.display.HTML at 0x1002eb7d0>"
}
],
"prompt_number": 14
},
{
"cell_type": "code",
"collapsed": false,
"input": "# grouped-bar \ncategories = ['giraffes', 'orangutans', 'monkeys']; \nSF = {'name': 'SF Zoo', \n 'x': categories, \n 'y': [20, 14, 23],\n 'type': 'bar'}\nLA = {'name': 'LA Zoo',\n 'x': categories, \n 'y': [12,18,29],\n 'type': 'bar'}\nlayout = {\n 'barmode': 'group',\n 'xaxis': {'type': 'category'},\n 'categories': categories}\npy.iplot([LA, SF], layout=layout)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/6/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 16,
"text": "<IPython.core.display.HTML at 0x1040d5390>"
}
],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": false,
"input": "layout = {'barmode': 'stack', \n 'xaxis': {'type': 'category'},\n 'categories': categories}\npy.iplot([SF, LA], layout=layout)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/7/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 17,
"text": "<IPython.core.display.HTML at 0x104c86fd0>"
}
],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": "categories=['giraffes', 'orangutans', 'monkeys']\nSF = {'name': 'SF Zoo', \n 'x': categories, \n 'y': [20, 14, 23],\n 'type': 'bar',\n 'marker':{\n 'color': 'orange',\n 'line': {'color': 'grey', \n 'width': 3}}\n }\n\nLA = {'name': 'LA Zoo',\n 'x': categories, \n 'y': [12,18,29],\n 'type': 'bar',\n 'marker': {'color': 'rgb(111, 168, 220)',\n 'line': {'color': 'grey',\n 'width': 3}}\n }\n\nlayout = {\n 'title': 'Animal Population',\n 'barmode': 'group',\n 'yaxis': {'name': '# of animals (thousands)'},\n 'xaxis': {'type': 'category'},\n 'categories': categories,\n 'bargap': 0.25,\n 'bargroupgap': 0.3,\n 'bardir': 'v'}\n\npy.iplot([LA, SF], layout=layout)\n",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/8/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 20,
"text": "<IPython.core.display.HTML at 0x104c86210>"
}
],
"prompt_number": 20
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Error Bars"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# Error Bars \ndata = {'x': [0,1,2],\n 'y': [6,10,2],\n 'error_y': {'type': 'data',\n 'array': [1, 2, 3],\n 'visible': True}}\npy.iplot([data])",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/9/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 22,
"text": "<IPython.core.display.HTML at 0x10073c7d0>"
}
],
"prompt_number": 22
},
{
"cell_type": "code",
"collapsed": false,
"input": "# percent-error-bar \ndata = {'x': [0,1,2],\n 'y': [6,8,4],\n 'error_y': {'type': 'percent',\n 'value': 50,\n 'visible': True}}\npy.iplot([data])",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/10/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 23,
"text": "<IPython.core.display.HTML at 0x104c943d0>"
}
],
"prompt_number": 23
},
{
"cell_type": "code",
"collapsed": false,
"input": "categories = ['Trial 1', 'Trial 2', 'Trial 3']\ncontrol = {'x': categories, \n 'y': [3, 6, 4],\n 'type': 'bar',\n 'marker':{'color': 'rgb(74, 134, 232)'},\n 'error_y': {'type': 'data',\n 'array': [1, 0.5, 1.5],\n 'visible': True,\n 'color': 'rgb(67, 67, 67)'}}\nexp = {'x': categories,\n 'y': [4, 7, 3],\n 'type': 'bar',\n 'marker':{'color':'rgb(111, 168, 220)'},\n 'error_y': {'type': 'data',\n 'array': [0.5, 1, 2],\n 'visible': True,\n 'color': 'rgb(67, 67, 67)'}}\nlayout = {'barmode': 'group'}\n\npy.iplot([control, exp], layout=layout)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/11/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 25,
"text": "<IPython.core.display.HTML at 0x104ac1790>"
}
],
"prompt_number": 25
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Box Plots"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# basic-box-plot \nbox1 = {'y': [0, 1, 2, 4],\n 'type': 'box'}\nbox2 = {'y': [1,2,4,5,8],\n 'type': 'box'}\npy.iplot([box1, box2])",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/12/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 26,
"text": "<IPython.core.display.HTML at 0x104ac1990>"
}
],
"prompt_number": 26
},
{
"cell_type": "code",
"collapsed": false,
"input": "# jitter \nfrom numpy import *\nbox = {'y': random.randn(50),\n 'type': 'box',\n 'boxpoints': 'all',\n 'jitter': 0.3, \n 'pointpos': -1.8} \npy.iplot([box])\n",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/13/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 27,
"text": "<IPython.core.display.HTML at 0x1040d53d0>"
}
],
"prompt_number": 27
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Histograms"
},
{
"cell_type": "code",
"collapsed": false,
"input": "from numpy import *\nx = random.randn(500) # normally distributed vector\ndata = {'x': x,\n 'type': 'histogramx'}\npy.iplot([data])",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/14/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 28,
"text": "<IPython.core.display.HTML at 0x104c94790>"
}
],
"prompt_number": 28
},
{
"cell_type": "code",
"collapsed": false,
"input": "# stacked-histo \nfrom numpy import *\nx0 = random.randn(500)\nx1 = random.randn(500)+1\ndata0 = {'x': x0,\n 'type': 'histogramx'}\ndata1 = {'x': x1,\n 'type': 'histogramx'}\nlayout = {'barmode': 'stack'}\npy.iplot([data0, data1], layout=layout)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/15/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 29,
"text": "<IPython.core.display.HTML at 0x104c94990>"
}
],
"prompt_number": 29
},
{
"cell_type": "code",
"collapsed": false,
"input": "layout = {'barmode': 'overlay'} \npy.iplot([data0, data1], layout=layout)\n",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/16/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 30,
"text": "<IPython.core.display.HTML at 0x104c86b50>"
}
],
"prompt_number": 30
},
{
"cell_type": "code",
"collapsed": false,
"input": "# style-histo \nfrom numpy import *\nx0 = random.randn(500)\nx1 = random.randn(500)+1\ndata0 = {'x': x0,\n 'type': 'histogramx',\n 'name': 'control',\n 'marker':{\n 'color': 'rgba(255,0,255,0.75)',\n 'opacity': 0.75,\n },\n 'autobinx': False,\n 'xbins':{\n 'start': -3.2,\n 'end': 2.8,\n 'size': 0.2\n },\n 'histnorm': 'count'\n}\ndata1 = {'x': x1,\n 'name': 'experiment',\n 'type': 'histogramx',\n 'marker':{\n 'color': 'rgba(255, 217, 102,0.75)',\n 'opacity': 0.75},\n 'autobinx': False,\n 'xbins':{\n 'start': -1.8,\n 'end': 4.2,\n 'size': 0.2\n }\n }\n\nlayout = {'barmode': 'overlay',\n 'bargap': 0.25,\n 'bargroupgap': 0.3,\n 'bardir': 'v',\n 'title': 'Sampled Results',\n 'xaxis': {'title': 'Value'},\n 'yaxis': {'title': 'Count'}} \npy.iplot([data0, data1], layout=layout)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/19/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 39,
"text": "<IPython.core.display.HTML at 0x104c94b50>"
}
],
"prompt_number": 39
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "2D Histograms"
},
{
"cell_type": "code",
"collapsed": false,
"input": "from numpy import *\nx = random.randn(500)\ny = random.randn(500)+1\ndata = {'x': x, 'y': y,\n 'type': 'histogram2d'}\npy.iplot([data])",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/20/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 40,
"text": "<IPython.core.display.HTML at 0x104c86990>"
}
],
"prompt_number": 40
},
{
"cell_type": "code",
"collapsed": false,
"input": "from numpy import *\nx = random.randn(500)\ny = random.randn(500)+1\ndata = {'x': x, \n 'y': y,\n 'type': 'histogram2d',\n 'autobinx': False,\n 'xbins': {\n 'start': -3,\n 'end': 3,\n 'size': 0.1\n },\n 'autobiny': False,\n 'ybins': {\n 'start': -2.5,\n 'end': 4,\n 'size': 0.1\n },\n 'scl': [[0,\"rgb(12,51,131)\"],\\\n [0.25,\"rgb(10,136,186)\"],\\\n [0.5,\"rgb(242,211,56)\"],\\\n [0.75,\"rgb(242,143,56)\"],\\\n [1,\"rgb(217,30,30)\"]],\n 'histnorm': 'probability'\n}\n\nlayout = {\n 'xaxis':{\n 'range':[-2,2],\n 'autorange':False\n },'yaxis':{\n 'range':[-1,3],\n 'autorange':False \n },\n 'width':520,'height':380,\n 'autosize':False\n }\n\npy.iplot([data],layout=layout)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/21/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 41,
"text": "<IPython.core.display.HTML at 0x104ac1a90>"
}
],
"prompt_number": 41
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Heatmaps"
},
{
"cell_type": "code",
"collapsed": false,
"input": "# basic-heatmap \nz = [[1., 20., 30 ],\\\n [20., 1., 60 ],\\\n [30., 60., 1.]]\ndata = {'z': z,\n 'type': 'heatmap'}\npy.iplot([data])\n",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/22/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 42,
"text": "<IPython.core.display.HTML at 0x104c94250>"
}
],
"prompt_number": 42
},
{
"cell_type": "code",
"collapsed": false,
"input": "x = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']\ny = ['Morning', 'Afternoon', 'Evening']\nz = [[1., 20., 30, 50, 1],\\\n [20., 1., 60, 80, 30 ],\\\n [30., 60., 1., -10, 20]]\ndata = {'x': x,\n 'y': y,\n 'z': z,\n 'type': 'heatmap'}\npy.iplot([data])\n",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/23/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 43,
"text": "<IPython.core.display.HTML at 0x104ac1ad0>"
}
],
"prompt_number": 43
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": "Mixed Types"
},
{
"cell_type": "code",
"collapsed": false,
"input": "from numpy import *\nx0 = linspace(0, 5, 15)\ny0 = sin(x0) + random.rand(15)\ndata0 = {'x': x0,'y': y0,\n 'type': 'scatter'}\n\nx1 = [0, 1, 2, 3, 4, 5]\ny1 = [1, 0.5, 0.7, -1.2, 0.3, 0.4]\ndata1 = {'x': x1,'y': y1,\n 'type': 'bar'}\n\npy.iplot([data0, data1])",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/24/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 44,
"text": "<IPython.core.display.HTML at 0x104ac19d0>"
}
],
"prompt_number": 44
},
{
"cell_type": "code",
"collapsed": false,
"input": "from numpy import *\n \nx0 = random.randn(100)/5. + 0.5 \ny0 = random.randn(100)/5. + 0.5 \n \nx1 = random.rayleigh(size=80)/7. + 0.1\ny1 = random.rayleigh(size=80)/8. + 1.1\n \ny = concatenate([y0,y1])\nx = concatenate([x0,x1])\n\ndata0 = {'x': x0, 'y': y0, \n 'marker':{'symbol':'circle'},\n 'type': 'scatter', 'mode': 'markers'}\ndata1 = {'x': x1, 'y': y1, \n 'marker':{'symbol':'cross'},\n 'type': 'scatter', 'mode': 'markers'}\n \ndata_hist = {'x': x, 'y': y, \n 'type':'histogram2d'}\n\npy.iplot([data0,data1,data_hist])\n",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n"
},
{
"html": "<iframe height=\"650\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~chriddyp/25/600/600\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 45,
"text": "<IPython.core.display.HTML at 0x104cb6fd0>"
}
],
"prompt_number": 45
},
{
"cell_type": "code",
"collapsed": false,
"input": "",
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment