Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!
Note: Ternary Plots are available in version 1.9.10+
Run pip install plotly --upgrade to update your Plotly version
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)
from IPython.display import display, HTML
display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))
#! 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')
/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. "You should import from nbconvert instead.", ShimWarning) /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. warnings.warn('Did you "Save" this notebook before running this command? '