Skip to content

Instantly share code, notes, and snippets.

@snoble
Created November 28, 2015 04:10
Show Gist options
  • Save snoble/b28d4265a6436dacddb0 to your computer and use it in GitHub Desktop.
Save snoble/b28d4265a6436dacddb0 to your computer and use it in GitHub Desktop.
Simple Contour Plot
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id="myDiv"><!-- Plotly chart will be drawn inside this DIV --></div>
<script>
<!-- JAVASCRIPT CODE GOES HERE -->
</script>
</body>
var size = 100, x = new Array(size), y = new Array(size), z = new Array(size), i, j;
for(var i = 0; i < size; i++) {
x[i] = y[i] = -2 * Math.PI + 4 * Math.PI * i / size;
z[i] = new Array(size);
}
for(var i = 0; i < size; i++) {
for(j = 0; j < size; j++) {
var r2 = x[i]*x[i] + y[j]*y[j];
z[i][j] = Math.sin(x[i]) * Math.cos(y[j]) * Math.sin(r2) / Math.log(r2+1);
}
}
var data = [ {
z: z,
x: x,
y: y,
type: 'contour'
}
];
var layout = {
title: 'Simple Contour Plot'
}
Plotly.newPlot('myDiv', data, layout);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment