title: How to render matplotlib plots in ipython
body: <p>I have a container running with Python/JupyterLab and all of my dependencies. I start it with:</p>
  <pre class="lang-sh prettyprint-override"><code>docker run --rm -it -p 8888:8888 \
    --mount type=bind,source=/project,target=/work \
    python-3.9.1-jupyterlab
  </code></pre>
  <p>It launches jupyterlab and I can connect through the browser. Everything is good.</p>
  <hr />
  <p>Now I am experimenting with using VSCode as a Python IDE. It is helpful to attach a shell from VSCode to my container so I can run iPython and edit my code all in one place. I run &quot;attach shell&quot; from the VSCode Docker extension:</p>
  <pre><code>docker exec -it {containerID} bash &lt;
  </code></pre>
  <p>Then I open an iPython shell:</p>
  <pre class="lang-sh prettyprint-override"><code>jo@:~/work $ ipython --pylab
  
  Python 3.9.1
  IPython 7.20.0 -- An enhanced Interactive Python.
  Using matplotlib backend: agg
  
  In [1]: matplotlib.get_backend()
  Out[1]: 'agg'
  
  In [2]: import matplotlib.pyplot as plt
  
  In [3]: plt.plot([1.6, 2.7])
  Out[3]: [&lt;matplotlib.lines.Line2D at 0x7f5ed0ed8d30&gt;]
  
  In [4]: plt.show()
  
  In [5]: %matplotlib inline
  
  In [6]: plt.plot([1.6, 2.7])
  Out[6]: [&lt;matplotlib.lines.Line2D at 0x7f5ed0df5d60&gt;]
  &lt;Figure size 432x288 with 1 Axes&gt;
  
  In [7]: plt.show()
  
  </code></pre>
  <p><strong>I cannot see any plots</strong>. I have tried rendering them with different backends (default was 'agg'). I am thinking this is because the kernel -- executing on the container -- cannot make use of the host graphics (i.e., kernel can render plots but cannot display them). Perhaps I do not have host/container ports mapped properly.</p>
  <p>Could someone provide some guidance on things to try? <a href="https://github.com/gitjeff05/jupyterlab-minimalist-image/tree/master/dockerfiles/pytorch" rel="nofollow noreferrer">Here is the image for the container I am using</a>.</p>