{ "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", "Note: Ternary Plots are available in version 1.9.10+
Run pip install plotly --upgrade to update your Plotly version" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Basic Ternary Contour Plot" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", "\n", "import json\n", "import urllib\n", "\n", "url = 'https://gist.githubusercontent.com/davenquinn/988167471993bc2ece29/raw/f38d9cb3dd86e315e237fde5d65e185c39c931c2/data.json'\n", "response = urllib.urlopen(url).read()\n", "data = json.loads(response)\n", "\n", "colors = ['#8dd3c7','#ffffb3','#bebada',\n", " '#fb8072','#80b1d3','#fdb462',\n", " '#b3de69','#fccde5','#d9d9d9',\n", " '#bc80bd','#ccebc5','#ffed6f'];\n", "\n", "# generate a,b and c from JSON data..\n", "traces = []\n", "color_iter = iter(colors)\n", "for i in data.keys():\n", " trace = dict(text=i,\n", " type='scatterternary',\n", " a=[ k['clay'] for k in data[i] ],\n", " b=[ k['sand'] for k in data[i] ],\n", " c=[ k['silt'] for k in data[i] ],\n", " mode='lines',\n", " line=dict(color='#444'),\n", " fill='toself',\n", " fillcolor=color_iter.next()\n", " )\n", " traces.append(trace)\n", " \n", "layout = {\n", " 'title': 'Simple Ternary Contour Plot with Python',\n", " 'ternary': \n", " {'sum':100,\n", " 'aaxis':{'title': 'clay', 'ticksuffix':'%', 'min': 0.01, 'linewidth':2, 'ticks':'outside' },\n", " 'baxis':{'title': 'sand', 'ticksuffix':'%', 'min': 0.01, 'linewidth':2, 'ticks':'outside' },\n", " 'caxis':{'title': 'silt','ticksuffix':'%', 'min': 0.01, 'linewidth':2, 'ticks':'outside' }},\n", " 'showlegend': False \n", "}\n", "\n", "figure = dict(data=traces, layout=layout)\n", "py.iplot(figure, validate=False)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", " \"You should import from nbconvert instead.\", ShimWarning)\n", "/Library/Frameworks/Python.framework/Versions/2.7/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-contour.ipynb', 'python/ternary-contour/', 'Python Ternary Contour Plots | plotly',\n", " 'How to make Ternary Contour Plots in Python with Plotly.',\n", " name = 'Ternary Contour Plots',\n", " thumbnail='thumbnail/ternary-contour.jpg', language='python',\n", " has_thumbnail='true', display_as='scientific', order=10,\n", " ipynb= '~notebook_demo/40')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "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.11" } }, "nbformat": 4, "nbformat_minor": 1 }