Insert figure into iPython markdown cell
Question: In iPython I create an image in one cell using the Pandas plot function. In a
different markdown cell in the same notebook I would like to add this figure
inline.

Is it possible to reference notebook internal figures in a markdown cell
without saving them to disk?


Answer: You can do it easily if you keep the
[Axes](http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes) instance
when creating the figure:

    
    
    t = arange(0,6,0.01)
    x = sin(t)
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(t,x)
    

If you're using pandas plotting functions, first create the axes as before and
then pass the instance to the pandas plotting function as argument:
`pandas.DataFrame.plot(ax=ax)`. An example:

    
    
    from pandas import Series, date_range
    ts = Series(randn(1000), index=date_range('1/1/2000', periods=1000))
    ts = ts.cumsum()
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ts.plot(ax=ax)
    

Then you can reuse the same figure in another cell:

    
    
    display(ax.get_figure())
    

