Function plot
HTML
<script src="http://mbostock.github.com/d3/d3.js"></script>
<div id="graph"></div>
CSS
path {
stroke: steelblue;
stroke-width: 1;
fill: none;
}
.axis {
shape-rendering: crispEdges;
}
.x.axis line {
stroke: lightgrey;
}
.x.axis .minor {
stroke-opacity: .5;
}
.x.axis path {
display: none;
}
.y.axis line, .y.axis path {
fill: none;
stroke: #000;
}
JavaScript
var m = [20, 20, 20, 80];
var width = 500 - m[1] - m[3];
var height = 300 - m[0] - m[2];
var kB = 1.38066E-23; // Boltzmann's constant in J/K
var c = 3.0E8; // light speed
var h = 6.63E-34; // Planck's constant (JS)
var T = 5750; // Temperature K
// Longueurs d'ondes
var wlmin = 300E-9; // meter
var wlmax = 1000E-9; // meter
var sample = 700;
function blackbody_at_t(n){
if(n<1){
return 1
} else
}
var x1 = d3.scale.linear().domain([0, sample]).range([wlmin, wlmax]);
var data = d3.range(sample).map(function(d){ return {
wl: x1(d),
intensity: blackbody_at_t(x1(d))};
});
var x = d3.scale.linear().domain([wlmin, wlmax]).range([0, width]);
var y = d3.scale.linear().domain(d3.extent(data.map(function(d){return d.intensity;}))).range([height, 0]);
var line = d3.svg.line()
.x(function(d) { return x(d.wl); })
.y(function(d) { return y(d.intensity); })
var graph = d3.select("#graph")
.append("svg")
.attr("width", width + m[1] + m[3])
.attr("height", height + m[0] + m[2])
.append("g")
.attr("transform", "translate(" + m[3] + "," + m[0] + ")");
var xAxis = d3.svg.axis().scale(x).tickSize(-height).tickSubdivide(true).tickFormat(d3.format('e'));
graph.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
var yAxisLeft = d3.svg.axis().scale(y).orient("left").tickFormat(d3.format('s'));
graph.append("g")
.attr("class", "y axis")
.attr("transform", "translate(-25,0)")
.call(yAxisLeft);
graph.append("path").attr("d", line(data));