{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#### New to Plotly?\n", "Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/).\n", "
You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/python/getting-started/#start-plotting-online).\n", "
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Version Check\n", "Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'2.2.1'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly\n", "plotly.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Basic Example" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "data": [ { "mode": "markers", "transforms": [ { "groups": [ "Moe", "Larry", "Curly", "Moe", "Larry", "Curly", "Moe", "Larry", "Curly", "Moe", "Larry", "Curly" ], "styles": [ { "target": "Moe", "value": { "marker": { "color": "blue" } } }, { "target": "Larry", "value": { "marker": { "color": "red" } } }, { "target": "Curly", "value": { "marker": { "color": "black" } } } ], "type": "groupby" } ], "type": "scatter", "x": [ "Moe", "Larry", "Curly", "Moe", "Larry", "Curly", "Moe", "Larry", "Curly", "Moe", "Larry", "Curly" ], "y": [ 1, 6, 2, 8, 2, 9, 4, 5, 1, 5, 2, 8 ] } ], "layout": {} }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.offline as off\n", "\n", "off.init_notebook_mode(connected=True)\n", "\n", "subject = ['Moe','Larry','Curly','Moe','Larry','Curly','Moe','Larry','Curly','Moe','Larry','Curly']\n", "score = [1,6,2,8,2,9,4,5,1,5,2,8]\n", "\n", "data = [dict(\n", " type = 'scatter',\n", " x = subject,\n", " y = score,\n", " mode = 'markers',\n", " transforms = [dict(\n", " type = 'groupby',\n", " groups = subject,\n", " styles = [\n", " dict(target = 'Moe', value = dict(marker = dict(color = 'blue'))),\n", " dict(target = 'Larry', value = dict(marker = dict(color = 'red'))),\n", " dict(target = 'Curly', value = dict(marker = dict(color = 'black')))\n", " ]\n", " )]\n", ")]\n", "\n", "off.iplot({'data': data}, validate=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Reference\n", "See https://plotly.com/python/reference/ for more information and chart attribute options!" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", " Cloning https://github.com/plotly/publisher.git to /private/var/folders/k_/zf24qrfn2kg710j9pdrxzrz40000gn/T/pip-zRCB4h-build\n", " Requirement already satisfied (use --upgrade to upgrade): publisher==0.11 from git+https://github.com/plotly/publisher.git in /Users/chelsea/venv/venv2.7/lib/python2.7/site-packages\n" ] } ], "source": [ "from IPython.display import display, HTML\n", "\n", "display(HTML(''))\n", "display(HTML(''))\n", "\n", "! pip install git+https://github.com/plotly/publisher.git\n", "import publisher\n", "publisher.publish(\n", " 'groupby.ipynb', 'python/group-by/', 'Group By',\n", " 'How to use group by in Python with Plotly.',\n", " title = 'Group By | Plotly',\n", " has_thumbnail='true', thumbnail='thumbnail/groupby.jpg', \n", " language='python', uses_plotly_offline=True,\n", " page_type='example_index',\n", " display_as='transforms', order=2,\n", " ipynb= '~notebook_demo/194')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 2 }