{ "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": { "collapsed": false }, "source": [ "#### Version Check\n", "Note: Ternary Plots are available in version 1.9.10+\n", "Run pip install plotly --upgrade to update your Plotly version" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'1.12.1'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly \n", "plotly.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Basic Ternary Plot with Markers" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "\n", "rawData = [\n", " {'journalist':75,'developer':25,'designer':0,'label':'point 1'},\n", " {'journalist':70,'developer':10,'designer':20,'label':'point 2'},\n", " {'journalist':75,'developer':20,'designer':5,'label':'point 3'},\n", " {'journalist':5,'developer':60,'designer':35,'label':'point 4'},\n", " {'journalist':10,'developer':80,'designer':10,'label':'point 5'},\n", " {'journalist':10,'developer':90,'designer':0,'label':'point 6'},\n", " {'journalist':20,'developer':70,'designer':10,'label':'point 7'},\n", " {'journalist':10,'developer':20,'designer':70,'label':'point 8'},\n", " {'journalist':15,'developer':5,'designer':80,'label':'point 9'},\n", " {'journalist':10,'developer':10,'designer':80,'label':'point 10'},\n", " {'journalist':20,'developer':10,'designer':70,'label':'point 11'},\n", "];\n", "\n", "def makeAxis(title, tickangle): \n", " return {\n", " 'title': title,\n", " 'titlefont': { 'size': 20 },\n", " 'tickangle': tickangle,\n", " 'tickfont': { 'size': 15 },\n", " 'tickcolor': 'rgba(0,0,0,0)',\n", " 'ticklen': 5,\n", " 'showline': True,\n", " 'showgrid': True\n", " }\n", "\n", "data = [{ \n", " 'type': 'scatterternary',\n", " 'mode': 'markers',\n", " 'a': [i for i in map(lambda x: x['journalist'], rawData)],\n", " 'b': [i for i in map(lambda x: x['developer'], rawData)],\n", " 'c': [i for i in map(lambda x: x['designer'], rawData)],\n", " 'text': [i for i in map(lambda x: x['label'], rawData)],\n", " 'marker': {\n", " 'symbol': 100,\n", " 'color': '#DB7365',\n", " 'size': 14,\n", " 'line': { 'width': 2 }\n", " },\n", " }]\n", "\n", "layout = {\n", " 'ternary': {\n", " 'sum': 100,\n", " 'aaxis': makeAxis('Journalist', 0),\n", " 'baxis': makeAxis('
Developer', 45),\n", " 'caxis': makeAxis('
Designer', -45)\n", " },\n", " 'annotations': [{\n", " 'showarrow': False,\n", " 'text': 'Simple Ternary Plot with Markers',\n", " 'x': 0.5,\n", " 'y': 1.3,\n", " 'font': { 'size': 15 }\n", " }]\n", "}\n", "\n", "fig = {'data': data, 'layout': layout}\n", "py.iplot(fig, validate=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Reference\n", "See https://plotly.com/python/reference/#scatterternary for more information and chart attribute options!" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "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 /var/folders/ld/6cl3s_l50wd40tdjq2b03jxh0000gp/T/pip-y1reaee3-build\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.10\n", " Uninstalling publisher-0.10:\n", " Successfully uninstalled publisher-0.10\n", " Running setup.py install for publisher ... \u001b[?25l-\b \b\\\b \b|\b \bdone\n", "\u001b[?25hSuccessfully installed publisher-0.10\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/brandendunbar/Desktop/test/venv/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead.\n", " \"You should import from nbconvert instead.\", ShimWarning)\n", "/Users/brandendunbar/Desktop/test/venv/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning: Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", " warnings.warn('Did you \"Save\" this notebook before running this command? '\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 --upgrade\n", "import publisher\n", "publisher.publish(\n", " 'ternary.ipynb', 'python/ternary-plots/', 'Python Ternary Plots | plotly',\n", " 'How to make Ternary plots in Python with Plotly.',\n", " name = 'Ternary Plots',\n", " thumbnail='thumbnail/ternary.jpg', language='python',\n", " page_type='example_index', has_thumbnail='true', display_as='scientific', order=9,\n", " ipynb= '~notebook_demo/39') " ] }, { "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": 0 }