Simple contour plot with Plotly.js.
Created
November 28, 2015 04:10
-
-
Save snoble/b28d4265a6436dacddb0 to your computer and use it in GitHub Desktop.
Simple Contour Plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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