%load_ext py_d3
%%d3
<script>
function pyexec(command) {
return new Promise(res => {
IPython.notebook.kernel.execute(command,
{iopub: {
output:
out => res(JSON.parse(eval(out.content.data["text/plain"])))
}},
{silent: false});
});
}
</script>
import json
import numpy as np
def get_data(count):
return json.dumps((np.random.rand(count)*10).tolist())
%%d3
<g></g>
<style>
element {
height: 25px;
}
div.bar {
display: inline-block;
width: 20px;
height: 75px;
margin-right: 2px;
background-color: teal;
}
</style>
<script>
pyexec("get_data(10)")
.then(dataset => {
d3.select("g").selectAll("div")
.data(dataset)
.enter()
.append("div")
.attr("class", "bar")
.style("height", d => {
let barHeight = d * 5;
return barHeight + "px";
});
});
</script>