### graph displayed twice while overloading _repr___svg___ for notebook

Julien Schueller | PHIMECA <schueller <at> phimeca.com>

2014-12-16 11:28:26 GMT

Hello,
I'm having trouble overloading _repr___svg___ for graph inlining in the notebook; my object is displayed
twice if I call plt.plot just before.
I assumed a figure was left open or something, but even if I call plt.close('all') between the matplotlib
calls, the result remains the same.
I did some imports first:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from scipy.stats import norm
import sys
import io
print('matplotlib version %s' % matplotlib.____version____)
import IPython
print('IPython version %s' % IPython.____version____)
Here'my object:
class NormGraph(object):
def ____init____(self):
super(NormGraph, self).____init____()
def _repr___svg___(self):
if sys.version_info[0] >= 3:
output = io.StringIO()
else:
output = io.BytesIO()
self._fig = plt.figure()
axes_kwargs = {}
plot_kwargs = {}
self._ax = [self._fig.add_subplot(111, **axes_kwargs)]
x = np.arange(-10, 10, 0.001)
y = norm.pdf(x,0,2)
self._ax[0].plot(x, y, **plot_kwargs)
self._fig.savefig(output, format='svg')
return output.getvalue()
Then a basic call to pyplot:
%matplotlib inline
plt.plot(0, 1)
Then if I try to inline my object it's displayed twice:
NormGraph()
I atached the complete notebook.
--
--
Julien Schueller
Phimeca Engineering
www.phimeca.com

_______________________________________________
IPython-User mailing list
IPython-User <at> scipy.org
http://mail.scipy.org/mailman/listinfo/ipython-user