class Power(object):
def __init__(self, power):
self.power = power
%matplotlib inline
import numpy as np
from IPython.core.pylabtools import print_figure
import matplotlib.pyplot as plt
def power_png(p):
fig, ax = plt.subplots()
x = np.linspace(-5,5)
y = x ** p.power
ax.plot(x,y)
buf = print_figure(fig, 'png')
plt.close(fig) # close the figure
return buf
p = Power(5)
df = get_ipython().display_formatter
png = df.formatters['image/png']
png.for_type(Power, power_png)
p