#!/usr/bin/env python # coding: utf-8 # #### New to Plotly? # 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/). #
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). #
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started! # #### Version Check # Note: Ternary Plots are available in version 1.9.10+
Run pip install plotly --upgrade to update your Plotly version # #### Basic Ternary Contour Plot # In[8]: import plotly.plotly as py import json import urllib url = 'https://gist.githubusercontent.com/davenquinn/988167471993bc2ece29/raw/f38d9cb3dd86e315e237fde5d65e185c39c931c2/data.json' response = urllib.urlopen(url).read() data = json.loads(response) colors = ['#8dd3c7','#ffffb3','#bebada', '#fb8072','#80b1d3','#fdb462', '#b3de69','#fccde5','#d9d9d9', '#bc80bd','#ccebc5','#ffed6f']; # generate a,b and c from JSON data.. traces = [] color_iter = iter(colors) for i in data.keys(): trace = dict(text=i, type='scatterternary', a=[ k['clay'] for k in data[i] ], b=[ k['sand'] for k in data[i] ], c=[ k['silt'] for k in data[i] ], mode='lines', line=dict(color='#444'), fill='toself', fillcolor=color_iter.next() ) traces.append(trace) layout = { 'title': 'Simple Ternary Contour Plot with Python', 'ternary': {'sum':100, 'aaxis':{'title': 'clay', 'ticksuffix':'%', 'min': 0.01, 'linewidth':2, 'ticks':'outside' }, 'baxis':{'title': 'sand', 'ticksuffix':'%', 'min': 0.01, 'linewidth':2, 'ticks':'outside' }, 'caxis':{'title': 'silt','ticksuffix':'%', 'min': 0.01, 'linewidth':2, 'ticks':'outside' }}, 'showlegend': False } figure = dict(data=traces, layout=layout) py.iplot(figure, validate=False) # In[1]: from IPython.display import display, HTML display(HTML('')) display(HTML('')) #! pip install git+https://github.com/plotly/publisher.git --upgrade import publisher publisher.publish( 'ternary-contour.ipynb', 'python/ternary-contour/', 'Python Ternary Contour Plots | plotly', 'How to make Ternary Contour Plots in Python with Plotly.', name = 'Ternary Contour Plots', thumbnail='thumbnail/ternary-contour.jpg', language='python', has_thumbnail='true', display_as='scientific', order=10, ipynb= '~notebook_demo/40') # In[ ]: