Last active
June 12, 2019 19:51
-
-
Save hugmanrique/66feaf792a215815287f3e1f6288462f to your computer and use it in GitHub Desktop.
Plot of a BivariateBeta(alpha_X, beta_X, alpha_Y, beta_Y) distribution (assumes X and Y are independent events)
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Plot</title> | |
</head> | |
<body> | |
<div id="plot"></div> | |
<script src="https://unpkg.com/@stdlib/stdlib@0.0.32/dist/stdlib-flat.min.js"></script> | |
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script> | |
<script src="plot.js"></script> | |
</body> | |
</html> |
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
const xStart = 0; | |
const xEnd = 1; | |
const xValues = 80; | |
const yStart = 0; | |
const yEnd = 1; | |
const yValues = 80; | |
const xDelta = (xEnd - xStart) / xValues; | |
const yDelta = (yEnd - yStart) / yValues; | |
const beta = (x, a, b) => stdlib.base.dists.beta.pdf(x, a, b); | |
function f(x, y) { | |
return beta(x, 2, 10) * beta(y, 6, 10); | |
} | |
const xData = []; | |
const yData = []; | |
const zData = []; | |
function loadData() { | |
for (let yIndex = 0; yIndex < yValues; yIndex++) { | |
const y = yStart + yDelta * yIndex; | |
zData[yIndex] = []; | |
yData[yIndex] = y; | |
for (let xIndex = 0; xIndex < xValues; xIndex++) { | |
const x = xStart + xDelta * xIndex; | |
zData[yIndex][xIndex] = f(x, y); | |
} | |
} | |
// Don't repeatedly compute x values for every y | |
for (let xIndex = 0; xIndex < xValues; xIndex++) { | |
const x = xStart + xDelta * xIndex; | |
xData[xIndex] = x; | |
} | |
} | |
loadData(); | |
const data = [ | |
{ | |
x: xData, | |
y: yData, | |
z: zData, | |
type: 'surface' | |
} | |
]; | |
const layout = { | |
autosize: false, | |
width: 800, | |
height: 800, | |
margin: { | |
l: 65, | |
r: 50, | |
b: 65, | |
top: 90 | |
}, | |
scene: { | |
xaxis: { | |
rangemode: 'tozero', | |
range: [xStart, xEnd] | |
}, | |
yaxis: { | |
rangemode: 'tozero', | |
range: [yStart, yEnd] | |
}, | |
camera: { | |
eye: { | |
x: -1.5, | |
y: -1.5, | |
} | |
} | |
} | |
}; | |
Plotly.newPlot('plot', data, layout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BiBeta(9, 10, 6, 10)