Show Sidebar Hide Sidebar

Ternary Contour Plots in Python

How to make Ternary Contour Plots in Python with Plotly.

New to Plotly?

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!

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 = ''
response = urllib.urlopen(url).read()
data = json.loads(response)

colors = ['#8dd3c7','#ffffb3','#bebada',

# generate a,b and c from JSON data..
traces = []
color_iter = iter(colors)
for i in data.keys():
    trace = dict(text=i,
        a=[ k['clay'] for k in data[i] ],
        b=[ k['sand'] for k in data[i] ],
        c=[ k['silt'] for k in data[i] ],
layout = {
    'title': 'Simple Ternary Contour Plot with Python',
         '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)
Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.