<div dir="ltr">If you've done '%matplotlib inline' previously, when you create a figure inside a cell, it will automatically be displayed at the end of that cell, separately from the regular repr system. So your _repr_svg_ method is getting called once, and the figure you create in that is being displayed again. I'm not sure what the best way to deal with that is.<br><br>Thomas<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 4 January 2015 at 17:31, Julien Schueller <span dir="ltr"><<a href="mailto:schueller@phimeca.com" target="_blank">schueller@phimeca.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
Hello,<br>
<br>
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.<br>
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.<br>
<br>
I did some imports first:<br>
import numpy as np<br>
import matplotlib.pyplot as plt<br>
import matplotlib<br>
from scipy.stats import norm<br>
import sys<br>
import io<br>
print('matplotlib version %s' % matplotlib.__version__)<br>
import IPython<br>
print('IPython version %s' % IPython.__version__)<br>
<br>
<br>
Here'my object:<br>
class NormGraph(object):<br>
    def __init__(self):<br>
        super(NormGraph, self).__init__()<br>
    def _repr_svg_(self):<br>
        if sys.version_info[0] >= 3:<br>
            output = io.StringIO()<br>
        else:<br>
            output = io.BytesIO()<br>
        self._fig = plt.figure()<br>
        axes_kwargs = {}<br>
        plot_kwargs = {}<br>
        self._ax = [self._fig.add_subplot(111, **axes_kwargs)]<br>
        x = np.arange(-10, 10, 0.001)<br>
        y = norm.pdf(x,0,2)<br>
        self._ax[0].plot(x, y, **plot_kwargs)<br>
        self._fig.savefig(output, format='svg')<br>
<br>
        return output.getvalue()<br>
<br>
<br>
Then a basic call to pyplot:<br>
%matplotlib inline<br>
plt.plot(0, 1)<br>
<br>
Then if I try to inline my object it's displayed twice:<br>
NormGraph()<br>
<br>
I atached the complete notebook.<br>
<br>
--<br>
Julien Schueller<br>
Phimeca Engineering<br>
<a href="http://www.phimeca.com" target="_blank">www.phimeca.com</a><br>
</div></div><br>_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
<br></blockquote></div><br></div>