# How to display plots only after \`plt.show()\` in jup notebook?

**URL:** <https://discourse.jupyter.org/t/how-to-display-plots-only-after-plt-show-in-jup-notebook/2863>\
**Category:** Notebook\
**Created:** [December 11, 2019, 8:05am UTC](https://discourse.jupyter.org/t/how-to-display-plots-only-after-plt-show-in-jup-notebook/2863 "2019-12-11T08:05:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)\
**Post date:** [December 11, 2019, 5:04pm UTC](https://discourse.jupyter.org/t/how-to-display-plots-only-after-plt-show-in-jup-notebook/2863/2 "2019-12-11T17:04:31Z")

</div>

There is a discussion [here](https://github.com/damianavila/RISE/issues/32#issuecomment-500521329) about using an extension to hide the code in a way that is compatible with RISE.

Supposing that is overkill for what you need, some suggestions:

- You can make the images show up with markdown on the slide.
- You can save an image file with matplotlib’s savefig()`in a cell where`%%capture`is the first line of the cell to suppress output of the plot generation from being displayed and then display the image of it when and where you want with`IPython.display` like at the bottom of [here](https://nbviewer.jupyter.org/github/fomightez/pymol-binder/blob/master/index.ipynb). Or use markdown to display the image.
- You can use the method [here](https://discourse.jupyter.org/t/is-there-a-way-to-save-the-output-of-a-cell/2489/4) to not display and capture the plot for display later, as illustrated next.

Expanded example of that last suggestion:  
cell ‘one’:

```auto
%%capture out
# of course you can show figures

def polynom(x):
    return 2 * x**2 - 20 * x + 2

X = np.linspace(-10, 10)
Y = polynom(X)
plt.plot(X, Y);

```

In cell ‘two’:

```auto
out.show() #currently `out()` alone works also.

```

As a followup to that last method, because you objected to code showing, you might find the plot’s returned object value details, text like `[<matplotlib.lines.Line2D at 0x7ff1855077f0>]` showing up to be unwanted as well. Trick to fix that so you just get only the plot from cell ‘one’ code:

In second cell:

```auto
# trick based on https://ipython.readthedocs.io/en/stable/api/generated/IPython.utils.capture.html#IPython.utils.capture.CapturedIO.outputs
# to get plot to print with out the object description / return value above 
# like `out.show()` results in. 
from IPython.display import display
display(out.outputs[1])

```

---

_[View the full topic](https://discourse.jupyter.org/t/how-to-display-plots-only-after-plt-show-in-jup-notebook/2863)._
