Here we show how to use rich representations in the notebook.
We first define a standard Python class that admits a SVG representation method. A Disc instance can be rendered as SVG in the notebook.
class Disc(object):
def __init__(self, size, color='red'):
self.size = size
self.color = color
def _repr_svg_(self):
return """<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<circle cx="{0:d}" cy="{0:d}" r="{0:d}" fill="{1:s}" />
</svg>""".format(self.size, self.color)
Disc(80, 'purple')
Other rich representation types are available in IPython.display
.
import IPython.display as dsp
Here, we can type mathematical equations in LaTeX, and they are nicely rendered in the notebook.
dsp.Math(r"\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}")