Ternary Contour Plots in JavaScript
How to create D3.js-based ternary contour plots. Examples of Ternary Contour Plots with plotly.
Plotly is known for its graphing libraries, but it's also a broader ecosystem for building interactive data apps, AI data analysis tools, and deploying and hosting Dash apps. Explore the full set of tools and platforms designed to help turn data into action. Discover Plotly.
var url = 'https://gist.githubusercontent.com/davenquinn/988167471993bc2ece29/raw/f38d9cb3dd86e315e237fde5d65e185c39c931c2/data.json';
var colors = ['#8dd3c7','#ffffb3','#bebada','#fb8072','#80b1d3','#fdb462','#b3de69','#fccde5','#d9d9d9','#bc80bd','#ccebc5','#ffed6f'];
d3.json(url, function(err, rawData) {
if(err) throw err;
plot(rawData);
});
function plot(rawData) {
var data = Object.keys(rawData).map(function(k, i) {
var pts = rawData[k];
pts = pts.concat(pts[0]);
return {
type: 'scatterternary',
mode: 'lines',
name: k,
a: pts.map(function(d) { return d.clay }),
b: pts.map(function(d) { return d.sand }),
c: pts.map(function(d) { return d.silt }),
line: { color: '#444' },
fill: 'toself',
fillcolor: colors[i],
hoveron:'fills+points'
};
});
var layout = {
ternary: {
sum: 100,
aaxis: makeAxis('Clay'),
baxis: makeAxis('Sand'),
caxis: makeAxis('Silt')
},
showlegend: false,
width: 700,
annotations: [{
showarrow: false,
text: 'Soil Types Fill Plot',
x: 0.15,
y: 1.1
}]
};
Plotly.newPlot('myDiv', data, layout);
}
function makeAxis(title) {
return {
title: {
text: title
},
ticksuffix: '%',
min: 0.01,
linewidth: 2,
ticks: 'outside',
ticklen: 8,
showgrid: true,
};
}
Inspired from Daven Quinn's block