This page was generated from doc/gallery/multiple-outputs.ipynb. Interactive online version: Binder badge.

Choosing from Multiple Outputs

By default, the last output of the selected cell is used as a thumbnail. If that’s what you want, you can simply use the nbsphinx-thumbnail cell tag.

If you want to specify one of multiple outputs, you can add a (zero-based) "output-index" to your "nbsphinx-thumbnail" cell metadata.

The following cell has this metadata, selecting the third output to be used as thumbnail in the gallery.

{
    "nbsphinx-thumbnail": {
        "output-index": 2
    }
}
[1]:
from IPython.display import Image

display(Image(url='https://jupyter.org/assets/nav_logo.svg'))
print('Hello!')
display(Image(filename='../images/notebook_icon.png'))
display(Image(url='https://www.python.org/static/img/python-logo-large.png', embed=True))
Hello!
../_images/gallery_multiple-outputs_2_2.png
---------------------------------------------------------------------------
gaierror                                  Traceback (most recent call last)
/usr/lib/python3.9/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1345             try:
-> 1346                 h.request(req.get_method(), req.selector, req.data, headers,
   1347                           encode_chunked=req.has_header('Transfer-encoding'))

/usr/lib/python3.9/http/client.py in request(self, method, url, body, headers, encode_chunked)
   1278         """Send a complete request to the server."""
-> 1279         self._send_request(method, url, body, headers, encode_chunked)
   1280

/usr/lib/python3.9/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1324             body = _encode(body, 'body')
-> 1325         self.endheaders(body, encode_chunked=encode_chunked)
   1326

/usr/lib/python3.9/http/client.py in endheaders(self, message_body, encode_chunked)
   1273             raise CannotSendHeader()
-> 1274         self._send_output(message_body, encode_chunked=encode_chunked)
   1275

/usr/lib/python3.9/http/client.py in _send_output(self, message_body, encode_chunked)
   1033         del self._buffer[:]
-> 1034         self.send(msg)
   1035

/usr/lib/python3.9/http/client.py in send(self, data)
    973             if self.auto_open:
--> 974                 self.connect()
    975             else:

/usr/lib/python3.9/http/client.py in connect(self)
   1440
-> 1441             super().connect()
   1442

/usr/lib/python3.9/http/client.py in connect(self)
    944         """Connect to the host and port specified in __init__."""
--> 945         self.sock = self._create_connection(
    946             (self.host,self.port), self.timeout, self.source_address)

/usr/lib/python3.9/socket.py in create_connection(address, timeout, source_address)
    822     err = None
--> 823     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    824         af, socktype, proto, canonname, sa = res

/usr/lib/python3.9/socket.py in getaddrinfo(host, port, family, type, proto, flags)
    953     addrlist = []
--> 954     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    955         af, socktype, proto, canonname, sa = res

gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
<ipython-input-1-913573d65a6a> in <module>
      4 print('Hello!')
      5 display(Image(filename='../images/notebook_icon.png'))
----> 6 display(Image(url='https://www.python.org/static/img/python-logo-large.png', embed=True))

/usr/lib/python3/dist-packages/IPython/core/display.py in __init__(self, data, url, filename, format, embed, width, height, retina, unconfined, metadata)
   1222         self.retina = retina
   1223         self.unconfined = unconfined
-> 1224         super(Image, self).__init__(data=data, url=url, filename=filename,
   1225                 metadata=metadata)
   1226

/usr/lib/python3/dist-packages/IPython/core/display.py in __init__(self, data, url, filename, metadata)
    628             self.metadata = {}
    629
--> 630         self.reload()
    631         self._check_data()
    632

/usr/lib/python3/dist-packages/IPython/core/display.py in reload(self)
   1254         """Reload the raw data from file or URL."""
   1255         if self.embed:
-> 1256             super(Image,self).reload()
   1257             if self.retina:
   1258                 self._retina_shape()

/usr/lib/python3/dist-packages/IPython/core/display.py in reload(self)
    658             # Deferred import
    659             from urllib.request import urlopen
--> 660             response = urlopen(self.url)
    661             data = response.read()
    662             # extract encoding from header, if there is one:

/usr/lib/python3.9/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    212     else:
    213         opener = _opener
--> 214     return opener.open(url, data, timeout)
    215
    216 def install_opener(opener):

/usr/lib/python3.9/urllib/request.py in open(self, fullurl, data, timeout)
    515
    516         sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 517         response = self._open(req, data)
    518
    519         # post-process response

/usr/lib/python3.9/urllib/request.py in _open(self, req, data)
    532
    533         protocol = req.type
--> 534         result = self._call_chain(self.handle_open, protocol, protocol +
    535                                   '_open', req)
    536         if result:

/usr/lib/python3.9/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    492         for handler in handlers:
    493             func = getattr(handler, meth_name)
--> 494             result = func(*args)
    495             if result is not None:
    496                 return result

/usr/lib/python3.9/urllib/request.py in https_open(self, req)
   1387
   1388         def https_open(self, req):
-> 1389             return self.do_open(http.client.HTTPSConnection, req,
   1390                 context=self._context, check_hostname=self._check_hostname)
   1391

/usr/lib/python3.9/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1347                           encode_chunked=req.has_header('Transfer-encoding'))
   1348             except OSError as err: # timeout error
-> 1349                 raise URLError(err)
   1350             r = h.getresponse()
   1351         except:

URLError: <urlopen error [Errno -2] Name or service not known>