{ "metadata": { "name": "", "signature": "sha256:58c644db34d9e5461534d26491f274cb4d126e9ec201c25b4818029333fee80f" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Quickstart with Plotly\n", "\n", "You can install `plotly` with `pip`:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " $ pip install plotly\n", "\n", "If that didn't work, try it with `sudo`:\n", "\n", " $ sudo pip install plotly\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import plotly" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The three subpackages you'll use in plotly are:\n", "\n", "* `plotly.plotly`\n", "* `plotly.graph_objs`\n", "* `plotly.tools`\n", "\n", "The `plotly.plotly` module is used when you need to *talk* to Plotly, make a plot, verify your credentials, etc. The `plotly.graph_objs` module contains all the definitions for the objects that make up a plotly figure. Finally, the `plotly.tools` module contains other useful functionality like storing your credentials, converting matplotlib figures, help with subplots, etc. \n", "\n", "You can access them via the above, but here's how we suggest importing these modules when you need them:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import plotly.plotly as py\n", "import plotly.tools as tls\n", "from plotly.graph_objs import * # note, __all__ is defined to make the `import *` safe for use." ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check that you have the latest version:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print plotly.check_version()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Newest version: 1.0.0\n", "Your version: 1.0.0\n", "\n" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Enter your plotly creds ([Sign up here](https://plot.ly/ssu) and [view your API key here](https://plot.ly/api/key))" ] }, { "cell_type": "code", "collapsed": false, "input": [ "py.sign_in('PythonAPI', 'ubpiol2cve')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, let's import some tools for later..." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import numpy as np\n", "import math\n", "import datetime\n", "import random" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Let's make one of our favorite graphs: the [Hans Rosling](http://www.ted.com/talks/hans_rosling_shows_the_best_stats_you_ve_ever_seen.html) bubble chart" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load up the data. You can just copy 'n paste this block, all we're doing is just downloading and loading this CSV: [https://gist.github.com/chriddyp/8818473/raw/d8c73ff66a190a84eb8c6c19df4d8865673234ca/2007gapminder.csv](https://gist.github.com/chriddyp/8818473/raw/d8c73ff66a190a84eb8c6c19df4d8865673234ca/2007gapminder.csv)" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import urllib2, StringIO, csv\n", "\n", "url = 'https://gist.github.com/chriddyp/8818473/raw/d8c73ff66a190a84eb8c6c19df4d8865673234ca/2007gapminder.csv'\n", "response = urllib2.urlopen(url).read()\n", "output = StringIO.StringIO(response)\n", "cr = csv.reader(output)\n", "def tryFloat(d):\n", " try:\n", " return float(d)\n", " except ValueError:\n", " return d\n", "\n", "data = [[tryFloat(dij) for dij in di] for di in cr]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 6 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's take a look at the first few rows:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "for row in data[0:10]:\n", " print row" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['Country', 'Population', 'Continent', 'lifeExp', 'gdpPercap']\n", "['Afghanistan', 31889923.0, 'Asia', 43.828, 974.5803384]\n", "['Albania', 3600523.0, 'Europe', 76.423, 5937.029526]\n", "['Algeria', 33333216.0, 'Africa', 72.301, 6223.367465]\n", "['Angola', 12420476.0, 'Africa', 42.731, 4797.231267]\n", "['Argentina', 40301927.0, 'Americas', 75.32, 12779.37964]\n", "['Australia', 20434176.0, 'Oceania', 81.235, 34435.36744]\n", "['Austria', 8199783.0, 'Europe', 79.829, 36126.4927]\n", "['Bahrain', 708573.0, 'Asia', 75.635, 29796.04834]\n", "['Bangladesh', 150448339.0, 'Asia', 64.062, 1391.253792]\n" ] } ], "prompt_number": 21 }, { "cell_type": "markdown", "metadata": {}, "source": [ "A figure in Plotly is completely represented by a nested dictionary structure that is sent as a serialized JSON string.\n", "\n", "You design figures by nesting `dict` and `list` structures. Each object in the JSON structure, be it a dictionary or list, has a class definition in the `plotly.graph_objs` python module.\n", "\n", "We define any visualized dataset as a *trace*. In this case, each *trace* will be a different continent. In this example, the dicts will have `x`, `y`, `text`, and `marker` size data." ] }, { "cell_type": "code", "collapsed": false, "input": [ "fig = Figure()\n", "for continent in ['Asia', 'Europe', 'Africa', 'Americas', 'Oceania']:\n", " fig['data'] += [Scatter(name=continent, # the \"name\" of this series is the Continent\n", " x=[row[4] for row in data if row[2] == continent], # \"x\" data is GDP Per Capit\n", " y=[row[3] for row in data if row[2] == continent], # \"y\" data is Life Expectancy\n", " text=[row[0] for row in data if row[2] == continent], # \"text\" data is the Country\n", " mode='markers',\n", " # specify the style of the individual scatter points\n", " marker=Marker(# scale the \"marker\" size to each Country's population\n", " size=[np.sqrt(row[1])/1.e3 for row in data if row[2] == continent],\n", " sizemode='area',\n", " sizeref=0.05,\n", " opacity=0.55\n", " )\n", " )]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 22 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The rest of the graph, like the axes, title, and legend, is described by a `Layout` dictionary-like object." ] }, { "cell_type": "code", "collapsed": false, "input": [ "fig['layout'] = Layout(xaxis=XAxis(title='GDP Per Capita'),\n", " yaxis=YAxis(title='Life Expectancy'),\n", " title='Hans Rosling Bubble Chart
2007'\n", " )" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 23 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Now, let's plot it. Giddyup!" ] }, { "cell_type": "code", "collapsed": false, "input": [ "py.iplot(fig, filename='My first plotly graph')" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 24 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plotly graphs are interactive. Hover over the points to view the text, click-and-drag to zoom, shift-click-and-drag to pan." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`py.iplot` saves the graph in your plotly account and embeds the graph in an IFrame inside the notebook. The [plotly - data and graph \u00bb](https://plot.ly/~IPython.Demo/1085) link in the lower right corner of the plot takes you to your newly created graph at a unique URL. Here is mine: [https://plot.ly/~PythonAPI/63/](https://plot.ly/~PythonAPI/63/).\n", "\n", "\n", "### Since your graph is online\n", "\n", "you can can share it with that [unique url](https://plot.ly/~PythonAPI/63/), or [embed](https://plot.ly/api/python/docs/iframes) your interactive graph in a web page.\n", "\n", "### You can also edit the graph in the plotly web-app\n", "\n", "![](https://dl.dropboxusercontent.com/s/nvn5sbbv3sk1ncs/Screenshot%202014-02-10%2022.41.13.png?dl=1&token_hash=AAFHcRou2vSDh-TsRnfZhXQdvGuCLvYy5cWBnlKYrWQgpQ)\n", "\n", "I edited the graph we just made inside the plotly web-app. It's a bit more minimal and the x-axis is logarithmic. All of the options available to customize your graph in the web-app are exposed through the API.\n", "\n", "Check out my new version here: [https://plot.ly/~ChrisP/21](https://plot.ly/~ChrisP/21). Below, I embed it in our notebook:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "tls.embed('ChrisP', '21')" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 25 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### In plotly, the data and the graph are always together, you can view the underlying data in every plotly graph.\n", "The graph that we just made can be viewed here: [https://plot.ly/~ChrisP/21](https://plot.ly/~ChrisP/21) and that graph's data lives here: [https://plot.ly/21/~ChrisP/data](https://plot.ly/21/~ChrisP/data).\n", "\n", "\n", "Usage, Your Data Rights, and Private Graphs\n", "-------------------------------------------\n", "\n", "When you make a graph on plotly, you retain the rights to your content (see our terms [here](https://plot.ly/tou)). You also control whether your graphs are public or private. Public plotting is free; for a lot of private use, you can get a Premium or Organizational plan (see http://plot.ly/plans). It's just like GitHub.\n", "\n", "By default, anyone can view the graphs at the unique URL. To make the graphs private, so that only you can see them when your logged in, set `world_readable` to `False`:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "t = [i*2*np.pi/100 for i in range(100)]\n", "trace = Scatter(x=[16.*np.sin(ti)**3 for ti in t],\n", " y=[13.*np.cos(ti)-5*np.cos(2*ti)-2*np.cos(3*ti)-np.cos(4*ti) for ti in t],\n", " line=Line(color='red', width=6))\n", "xaxis = XAxis(ticks='', showline=False, zeroline=False)\n", "yaxis = YAxis(ticks='', showline=False, zeroline=False)\n", "fig = Figure(data=[trace], layout=Layout(xaxis=xaxis, yaxis=yaxis))\n", "py.iplot(fig, filename=\"public hearts\", world_readable=True)" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 26 }, { "cell_type": "markdown", "metadata": {}, "source": [ "And the same graph, but with a private setting:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "py.iplot(fig, filename=\"private hearts\", world_readable=False)" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 27 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Preventing the graph from opening in your browser\n", "-------------------------------------------------\n", "\n", "If your plotting from your Python command line, using the method `py.plot`, your graphs will automatically open for you in your browser. To turn this off, include the keyword argument: `auto_open=False`. This will spit back the unique url that Plotly made for this graph." ] }, { "cell_type": "code", "collapsed": false, "input": [ "py.plot(fig, filename=\"unopened hearts\", auto_open=False)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 28, "text": [ "u'https://plot.ly/~PythonAPI/66'" ] } ], "prompt_number": 28 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plotting with NumPy, Datetime, and $\\LaTeX$\n", "---------------------------------------------------" ] }, { "cell_type": "code", "collapsed": false, "input": [ "fig = Figure() # this creates `data=Data()` and `layout=Layout()` objects for you if you don't specify them\n", "\n", "fig['data'] += [Box(y=np.random.randn(50), boxpoints='all', jitter=0.5, pointpos=-1.8) for i in range(10)]\n", "fig['layout'].update(title=\"NumPy Boxes\", showlegend=False)\n", "fig['layout']['yaxis'] = XAxis(zeroline=False, ticks='', showline=False)\n", "fig['layout']['xaxis'] = YAxis(ticks='', showgrid=False, showline=False)\n", "\n", "py.iplot(fig, filename='numpy boxes')" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 29 }, { "cell_type": "code", "collapsed": false, "input": [ "N = 500\n", "now = datetime.datetime.now()\n", "fig = Figure()\n", "trace = Scatter(mode='markers')\n", "trace['x'] = [datetime.timedelta(hours=i) + now for i in range(N)]\n", "trace['y'] = [np.sin(i*5*np.pi/N)*np.exp(-2.*i/N)+np.random.random()/3. for i in range(N)]\n", "fig['data'] += [trace]\n", "fig['layout']['title'] = 'Datetime Decay'\n", "\n", "# let's add a note about this plot!\n", "text = \"The date-formatted x-axis will increase it\\'s time-resolution when you zoom.\" \\\n", " \"
Click-and-drag your mouse on the plot to see how it responds!\"\n", "my_note = Annotation(text=text, xref='paper', yref='paper', showarrow=False, x=.9, y=.9)\n", "fig['layout']['annotations']=Annotations([my_note])\n", "\n", "py.iplot(fig, filename='Datetime Decay')" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 30 }, { "cell_type": "code", "collapsed": false, "input": [ "x = np.linspace(-7, 7, 100)\n", "y = [x]\n", "y += [y[0] - x**3/np.math.factorial(3)]\n", "y += [y[1] + x**5/np.math.factorial(5)]\n", "y += [y[2] - x**7/np.math.factorial(7)]\n", "y += [y[3] + x**9/np.math.factorial(9)]\n", "\n", "linestyle1 = Line(color='#7FDBFF', dash='dot')\n", "linestyle2 = Line(color='#0074D9')\n", "\n", "fig = Figure()\n", "fig['data'] += [Scatter(x=x, y=approx, line=linestyle1) for approx in y]\n", "fig['data'] += [Scatter(x=x, y=np.sin(x), line=linestyle2)]\n", "fig['data'].update([{'name':'trace{}'.format(i)} for i in range(len(fig['data']))]) # add some labels using Data's update method\n", "\n", "fig['layout']['title'] = '$\\\\sin(x)=\\sum\\limits_{k=0}^{\\infty}\\dfrac{(-1)^k x^{1+2k}}{(1+2k)!}$'\n", "fig['layout']['xaxis'] = XAxis(showgrid=False, showline=False, zeroline=False, ticks='')\n", "fig['layout']['yaxis'] = YAxis(range=[-4.5, 4.5], zeroline=False, ticks='', showline=False)\n", "fig['layout']['showlegend'] = False\n", "\n", "py.iplot(fig, filename='LaTeX')" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 31 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Flexible Axes and Subplots\n", "--------------------------\n", "\n", "Plotly abstracts subplots and insets as axes, so it's easy to let subplots share axes and interactivity.\n", "\n", "For example, this graph has two yaxes and two axes. Each column of plots share the same x-axis, and each row of plots share the same y-axis. Try zooming in any section of the plot (click-and-drag to zoom)!" ] }, { "cell_type": "code", "collapsed": false, "input": [ "fig = Figure()\n", "fig['layout'].update(xaxis1=XAxis(domain=[0,0.8]),\n", " xaxis2=XAxis(domain=[0.85,1.0]),\n", " yaxis1=YAxis(domain=[0,0.8]),\n", " yaxis2=YAxis(domain=[0.85,1.0]))\n", "\n", "fig['layout'].update(title=\"i <3 subplots\", showlegend=False)\n", "for key in ['xaxis1', 'xaxis2', 'yaxis1', 'yaxis2']:\n", " fig['layout'][key].update(showgrid=False, showline=False, zeroline=False)\n", "\n", "x0 = np.concatenate([np.random.randn(400), np.random.randn(400)+6])\n", "y0 = np.random.rayleigh(size=800)\n", "\n", "ybins = YBins(start=0, end=5, size=.2)\n", "xbins = XBins(start=-5, end=10, size=.6)\n", "\n", "hist2d = Histogram2d(x=x0, y=y0, ybins=ybins, xbins=xbins)\n", "\n", "marker = Marker(color=\"rgb(31, 119, 180)\")\n", "# histy = Histogramy(y=hist2d['y'], bardir='h', xaxis='x2', yaxis='y1', autobiny=False, ybins=ybins, marker=marker)\n", "histx1 = Histogramx(x=hist2d['y'], bardir='h', xaxis='x2', yaxis='y1', autobinx=False, xbins=ybins, marker=marker)\n", "histx = Histogramx(x=hist2d['x'], xaxis='x1', yaxis='y2', autobinx=False, xbins=xbins, marker=marker)\n", "fig['data'] += [hist2d, histx1, histx]\n", "\n", "py.iplot(fig, filename='histogram subplots')" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 32 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or, if you want a quicker (albeit less flexible) approach, check out the `get_suplots` function from the tools module:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "fig = tls.get_subplots(rows=4, columns=4, print_grid=True)\n", "fig['data'] += [Scatter(x=np.random.rand(20),\n", " y=np.random.rand(20),\n", " name='plot{}'.format(iii),\n", " mode='markers',\n", " xaxis='x{}'.format(iii),\n", " yaxis='y{}'.format(iii))\n", " for iii in range(1, 17)]\n", "fig['layout'].update(title='i really <3 subplots')\n", "py.iplot(fig, filename='a bunch of subplots')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "This is the format of your plot grid!\n", "[13]\t[14]\t[15]\t[16]\t\n", "[9]\t[10]\t[11]\t[12]\t\n", "[5]\t[6]\t[7]\t[8]\t\n", "[1]\t[2]\t[3]\t[4]\t\n", "\n" ] }, { "html": [ "" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 33 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Nice. Now you're ready to get started. Maybe all you need is a little more `help()`. You can run help on any of the classes defined by our API to get you going!" ] }, { "cell_type": "code", "collapsed": false, "input": [ "help(Scatter)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Help on class Scatter in module plotly.graph_objs.graph_objs:\n", "\n", "class Scatter(PlotlyTrace)\n", " | A dictionary-like object for representing a scatter plot in plotly.\n", " | \n", " | Example:\n", " | \n", " | py.plot([Scatter(name='tacters', x=[1,4,2,3], y=[1,6,2,1])])\n", " | \n", " | \n", " | Quick method reference:\n", " | \n", " | Scatter.update(dict1, **dict2)\n", " | Scatter.strip_style()\n", " | Scatter.get_data()\n", " | Scatter.to_graph_objs()\n", " | Scatter.validate()\n", " | Scatter.force_clean()\n", " | \n", " | Valid keys:\n", " | \n", " | x [required=True] (value=array-like of numbers, strings, datetimes):\n", " | The x coordinates from the (x,y) pair on the scatter plot.\n", " | \n", " | y [required=True] (value=array-like of numbers, strings, datetimes):\n", " | The y coordinates from the (x,y) pair on the scatter plot.\n", " | \n", " | text [required=False] (value=array-like of strings):\n", " | The text elements associated with every (x,y) pair on the scatter\n", " | plot. If the scatter 'mode' doesn't include 'text' then text will\n", " | appear on hover. If 'text' is included in 'mode', the entries in\n", " | 'text' will be rendered on the plot at the locations specified by\n", " | their corresponding (x, y) pair.\n", " | \n", " | name [required=False] (value=string):\n", " | The label associated with this trace. This name will appear in the\n", " | legend, in the column header in the spreadsheet, and on hover.\n", " | \n", " | mode [required=False] (value='lines' | 'markers' | 'text' |\n", " | 'lines+markers' | 'lines+text' | 'markers+text' | 'lines+markers+text'):\n", " | Plotting mode (style) for the scatter plot. If the mode includes\n", " | 'text' then the 'text' will appear at the (x,y) points, otherwise it\n", " | will appear on hover.\n", " | \n", " | marker [required=False] (value=Marker object | dictionary-like):\n", " | A dictionary-like object containing information about the marker\n", " | style of the scatter plot.\n", " | \n", " | For more, run `help(plotly.graph_objs.Marker)`\n", " | \n", " | line [required=False] (value=Line object | dictionary-like):\n", " | A dictionary-like object containing information about the line\n", " | connecting points on the scatter plot.\n", " | \n", " | For more, run `help(plotly.graph_objs.Line)`\n", " | \n", " | fill [required=False] (value='none' | 'tozeroy' | 'tonexty' | 'tozerox'\n", " | | 'tonextx):\n", " | Used to make area-style charts. Determines which area to fill with a\n", " | solid color.\n", " | \n", " | fillcolor [required=False] (value=str describing color):\n", " | If the 'fill' for a line is not 'none', the fill color will appear\n", " | in the specified fill area.\n", " | \n", " | Examples:\n", " | [\"'green'\", \"'rgb(0, 255, 0)'\", \"'rgba(0, 255, 0, 0.3)'\",\n", " | \"'hsl(120,100%,50%)'\", \"'hsla(120,100%,50%,0.3)'\"]\n", " | \n", " | opacity [required=False] (value=number: x in [0, 1]):\n", " | Sets the opacity, or transparency, of this object. Also known as the\n", " | alpha channel of colors, if the object's color is given in terms of\n", " | 'rgba', this does not need to be defined.\n", " | \n", " | showlegend [required=False] (value=bool: True | False):\n", " | Toggle whether or not this trace will show up in the legend.\n", " | \n", " | stream [required=False] (value=dictionary-like):\n", " | The stream dict that initializes traces as writable-streams, for use\n", " | with the real-time streaming API. See examples here:\n", " | http://nbviewer.ipython.org/github/plotly/Streaming-Demos\n", " | \n", " | xaxis [required=False] (value=string: 'x1' | 'x2' | 'x3' | etc.):\n", " | This key determines which xaxis the x coordinates in this trace will\n", " | reference in the figure. 'x' references layout['xaxis'] and 'x2'\n", " | references layout['xaxis2']. 'x1' will always refer to\n", " | layout['xaxis'] or layout['xaxis1'], they are the same.\n", " | \n", " | yaxis [required=False] (value=string: 'y1' | 'y2' | 'y3' | etc.):\n", " | This key determines which yaxis the y coordinates in this trace will\n", " | reference in the figure. 'y' references layout['yaxis'] and 'y2'\n", " | references layout['yaxis2']. 'y1' will always refer to\n", " | layout['yaxis'] or layout['yaxis1'], they are the same.\n", " | \n", " | error_y [required=False] (value=ErrorY object | dictionary-like):\n", " | A dictionary-like object describing vertical error bars that can be\n", " | drawn with this trace's (x, y) points.\n", " | \n", " | For more, run `help(plotly.graph_objs.ErrorY)`\n", " | \n", " | visible [required=False] (value=bool: True | False):\n", " | Toggles whether this will actually be visible in the rendered\n", " | figure.\n", " | \n", " | textfont [required=False] (value=Aw, snap! Undocumented!):\n", " | A dictionary-like object describing the font style of this scatter's\n", " | text elements. This only has an effect if 'text' is an array of\n", " | strings and 'mode' is set to include 'text'.\n", " | \n", " | For more, run `help(plotly.graph_objs.Font)`\n", " | \n", " | type [required=False] (value='scatter'):\n", " | Plotly identifier for this data's trace type. This defines how this\n", " | data dictionary will be handled. For example, 'scatter' type expects\n", " | x and y data-arrays corresponding to (x, y) coordinates wheras a\n", " | 'histogramx' only requires a single x array and a 'heatmap' type\n", " | requires x and y data-arrays as well as a z matrix.\n", " | \n", " | Method resolution order:\n", " | Scatter\n", " | PlotlyTrace\n", " | PlotlyDict\n", " | __builtin__.dict\n", " | __builtin__.object\n", " | \n", " | Methods inherited from PlotlyTrace:\n", " | \n", " | __init__(self, *args, **kwargs)\n", " | \n", " | ----------------------------------------------------------------------\n", " | Methods inherited from PlotlyDict:\n", " | \n", " | force_clean(self)\n", " | Attempts to convert to graph_objs and call force_clean() on values.\n", " | \n", " | Calling force_clean() on a PlotlyDict will ensure that the object is\n", " | valid and may be sent to plotly. This process will also remove any\n", " | entries that end up with a length == 0.\n", " | \n", " | Careful! This will delete any invalid entries *silently*.\n", " | \n", " | get_data(self)\n", " | Returns the JSON for the plot with non-data elements stripped.\n", " | \n", " | strip_style(self)\n", " | Strip style from the current representation.\n", " | \n", " | All PlotlyDicts and PlotlyLists are guaranteed to survive the\n", " | stripping process, though they made be left empty. This is allowable.\n", " | \n", " | Keys that will be stripped in this process are tagged with\n", " | `'type': 'style'` in the INFO dictionary listed in graph_objs_meta.py.\n", " | \n", " | This process first attempts to convert nested collections from dicts\n", " | or lists to subclasses of PlotlyList/PlotlyDict. This process forces\n", " | a validation, which may throw exceptions.\n", " | \n", " | Then, each of these objects call `strip_style` on themselves and so\n", " | on, recursively until the entire structure has been validated and\n", " | stripped.\n", " | \n", " | to_graph_objs(self)\n", " | Walk obj, convert dicts and lists to plotly graph objs.\n", " | \n", " | For each key in the object, if it corresponds to a special key that\n", " | should be associated with a graph object, the ordinary dict or list\n", " | will be reinitialized as a special PlotlyDict or PlotlyList of the\n", " | appropriate `kind`.\n", " | \n", " | update(self, dict1=None, **dict2)\n", " | Update current dict with dict1 and then dict2.\n", " | \n", " | This recursively updates the structure of the original dictionary-like\n", " | object with the new entries in the second and third objects. This\n", " | allows users to update with large, nested structures.\n", " | \n", " | Note, because the dict2 packs up all the keyword arguments, you can\n", " | specify the changes as a list of keyword agruments.\n", " | \n", " | Examples:\n", " | # update with dict\n", " | obj = Layout(title='my title', xaxis=XAxis(range=[0,1], domain=[0,1]))\n", " | update_dict = dict(title='new title', xaxis=dict(domain=[0,.8]))\n", " | obj.update(update_dict)\n", " | obj\n", " | {'title': 'new title', 'xaxis': {'range': [0,1], 'domain': [0,.8]}}\n", " | \n", " | # update with list of keyword arguments\n", " | obj = Layout(title='my title', xaxis=XAxis(range=[0,1], domain=[0,1]))\n", " | obj.update(title='new title', xaxis=dict(domain=[0,.8]))\n", " | obj\n", " | {'title': 'new title', 'xaxis': {'range': [0,1], 'domain': [0,.8]}}\n", " | \n", " | This 'fully' supports duck-typing in that the call signature is\n", " | identical, however this differs slightly from the normal update\n", " | method provided by Python's dictionaries.\n", " | \n", " | validate(self)\n", " | Recursively check the validity of the keys in a PlotlyDict.\n", " | \n", " | The valid keys constitute the entries in each object\n", " | dictionary in INFO stored in graph_objs_meta.py.\n", " | \n", " | The validation process first requires that all nested collections be\n", " | converted to the appropriate subclass of PlotlyDict/PlotlyList. Then,\n", " | each of these objects call `validate` and so on, recursively,\n", " | until the entire object has been validated.\n", " | \n", " | ----------------------------------------------------------------------\n", " | Data descriptors inherited from PlotlyDict:\n", " | \n", " | __dict__\n", " | dictionary for instance variables (if defined)\n", " | \n", " | __weakref__\n", " | list of weak references to the object (if defined)\n", " | \n", " | ----------------------------------------------------------------------\n", " | Data and other attributes inherited from PlotlyDict:\n", " | \n", " | __metaclass__ = \n", " | A meta class for PlotlyDict class creation.\n", " | \n", " | The sole purpose of this meta class is to properly create the __doc__\n", " | attribute so that running help(Obj), where Obj is a subclass of PlotlyDict,\n", " | will return information about key-value pairs for that object.\n", " | \n", " | ----------------------------------------------------------------------\n", " | Methods inherited from __builtin__.dict:\n", " | \n", " | __cmp__(...)\n", " | x.__cmp__(y) <==> cmp(x,y)\n", " | \n", " | __contains__(...)\n", " | D.__contains__(k) -> True if D has a key k, else False\n", " | \n", " | __delitem__(...)\n", " | x.__delitem__(y) <==> del x[y]\n", " | \n", " | __eq__(...)\n", " | x.__eq__(y) <==> x==y\n", " | \n", " | __ge__(...)\n", " | x.__ge__(y) <==> x>=y\n", " | \n", " | __getattribute__(...)\n", " | x.__getattribute__('name') <==> x.name\n", " | \n", " | __getitem__(...)\n", " | x.__getitem__(y) <==> x[y]\n", " | \n", " | __gt__(...)\n", " | x.__gt__(y) <==> x>y\n", " | \n", " | __iter__(...)\n", " | x.__iter__() <==> iter(x)\n", " | \n", " | __le__(...)\n", " | x.__le__(y) <==> x<=y\n", " | \n", " | __len__(...)\n", " | x.__len__() <==> len(x)\n", " | \n", " | __lt__(...)\n", " | x.__lt__(y) <==> x x!=y\n", " | \n", " | __repr__(...)\n", " | x.__repr__() <==> repr(x)\n", " | \n", " | __setitem__(...)\n", " | x.__setitem__(i, y) <==> x[i]=y\n", " | \n", " | __sizeof__(...)\n", " | D.__sizeof__() -> size of D in memory, in bytes\n", " | \n", " | clear(...)\n", " | D.clear() -> None. Remove all items from D.\n", " | \n", " | copy(...)\n", " | D.copy() -> a shallow copy of D\n", " | \n", " | fromkeys(...)\n", " | dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.\n", " | v defaults to None.\n", " | \n", " | get(...)\n", " | D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.\n", " | \n", " | has_key(...)\n", " | D.has_key(k) -> True if D has a key k, else False\n", " | \n", " | items(...)\n", " | D.items() -> list of D's (key, value) pairs, as 2-tuples\n", " | \n", " | iteritems(...)\n", " | D.iteritems() -> an iterator over the (key, value) items of D\n", " | \n", " | iterkeys(...)\n", " | D.iterkeys() -> an iterator over the keys of D\n", " | \n", " | itervalues(...)\n", " | D.itervalues() -> an iterator over the values of D\n", " | \n", " | keys(...)\n", " | D.keys() -> list of D's keys\n", " | \n", " | pop(...)\n", " | D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n", " | If key is not found, d is returned if given, otherwise KeyError is raised\n", " | \n", " | popitem(...)\n", " | D.popitem() -> (k, v), remove and return some (key, value) pair as a\n", " | 2-tuple; but raise KeyError if D is empty.\n", " | \n", " | setdefault(...)\n", " | D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D\n", " | \n", " | values(...)\n", " | D.values() -> list of D's values\n", " | \n", " | viewitems(...)\n", " | D.viewitems() -> a set-like object providing a view on D's items\n", " | \n", " | viewkeys(...)\n", " | D.viewkeys() -> a set-like object providing a view on D's keys\n", " | \n", " | viewvalues(...)\n", " | D.viewvalues() -> an object providing a view on D's values\n", " | \n", " | ----------------------------------------------------------------------\n", " | Data and other attributes inherited from __builtin__.dict:\n", " | \n", " | __hash__ = None\n", " | \n", " | __new__ = \n", " | T.__new__(S, ...) -> a new object with type S, a subtype of T\n", "\n" ] } ], "prompt_number": 34 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Check out more short Plotly-IPython Notebooks\n", "- [Plotly and Python](http://htmlpreview.github.com/?https://github.com/plotly/python-api/blob/1.0/notebooks/Plotly%20and%20Python.html)\n", "- [Plotly and matplotlib](http://htmlpreview.github.com/?https://github.com/plotly/python-api/blob/1.0/notebooks/Plotly%20and%20mpld3.html)\n", "- [Bubble Chart Explorer](http://nbviewer.ipython.org/github/plotly/IPython-plotly/blob/master/Bubble%20Chart%20Explorer.ipynb)\n", "- [Running MATLAB in IPython with Plotly Graphs](http://nbviewer.ipython.org/gist/anonymous/8868059)\n", "\n", "### See our full guidebook:\n", "- [Your Guide to Plotly](http://nbviewer.ipython.org/github/etpinard/plotly-python-doc/tree/1.0/)\n", "\n", "### More resources \n", "- [Plotly Documentation](https://plot.ly/API)\n", "- [Plotly GitHub](https://github.com/plotly)\n", "- [@plotlygraphs](http://twitter.com/plotlygraphs)\n", "- [Plotly Facebook](https://facebook.com/plotly)\n", "- [The Plotly Team](https://plot.ly/team)\n", "- " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Hearts* \n", "Team Plotly \n", "Montr\u00e9al | SF | Boston" ] } ], "metadata": {} } ] }