def svg_disc(radius, color): return """ """.format(radius, color) class Disc(object): def __init__(self, radius, color='red'): self.radius = radius self.color = color def _repr_svg_(self): return svg_disc(self.radius, self.color) Disc(60, 'purple') from IPython.display import display_javascript JS_TEMPLATE = """ // We load the d3.js library from the Web. require.config({paths: {d3: "http://d3js.org/d3.v3.min"}}); require(["d3"], function(d3) { // Example from http://bost.ocks.org/mike/bar/ // Define the data. var data = %s; // We normalize the data. var x = d3.scale.linear() .domain([0, d3.max(data)]) .range([0, 420]); // We define a categorical color map. var color = d3.scale.category10(); // We create the chart. d3.select(".chart") .selectAll("div") .data(data) .enter().append("div") .style("width", function(d) { return x(d) + "px"; }) .text(function(d) { return d; }); }); """ my_list = [2, 3, 5, 7, 11, 13] JS = JS_TEMPLATE % str(my_list) %%HTML
display_javascript(JS, raw=True)