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/lib64/python3.10/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1347             try:
-> 1348                 h.request(req.get_method(), req.selector, req.data, headers,
   1349                           encode_chunked=req.has_header('Transfer-encoding'))

/usr/lib64/python3.10/http/client.py in request(self, method, url, body, headers, encode_chunked)
   1275         """Send a complete request to the server."""
-> 1276         self._send_request(method, url, body, headers, encode_chunked)
   1277

/usr/lib64/python3.10/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1321             body = _encode(body, 'body')
-> 1322         self.endheaders(body, encode_chunked=encode_chunked)
   1323

/usr/lib64/python3.10/http/client.py in endheaders(self, message_body, encode_chunked)
   1270             raise CannotSendHeader()
-> 1271         self._send_output(message_body, encode_chunked=encode_chunked)
   1272

/usr/lib64/python3.10/http/client.py in _send_output(self, message_body, encode_chunked)
   1030         del self._buffer[:]
-> 1031         self.send(msg)
   1032

/usr/lib64/python3.10/http/client.py in send(self, data)
    968             if self.auto_open:
--> 969                 self.connect()
    970             else:

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

/usr/lib64/python3.10/http/client.py in connect(self)
    939         sys.audit("http.client.connect", self, self.host, self.port)
--> 940         self.sock = self._create_connection(
    941             (self.host,self.port), self.timeout, self.source_address)

/usr/lib64/python3.10/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/lib64/python3.10/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 -3] Temporary failure in name resolution

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.10/site-packages/IPython/core/display.py in __init__(self, data, url, filename, format, embed, width, height, retina, unconfined, metadata)
   1229         self.retina = retina
   1230         self.unconfined = unconfined
-> 1231         super(Image, self).__init__(data=data, url=url, filename=filename,
   1232                 metadata=metadata)
   1233

/usr/lib/python3.10/site-packages/IPython/core/display.py in __init__(self, data, url, filename, metadata)
    635             self.metadata = {}
    636
--> 637         self.reload()
    638         self._check_data()
    639

/usr/lib/python3.10/site-packages/IPython/core/display.py in reload(self)
   1261         """Reload the raw data from file or URL."""
   1262         if self.embed:
-> 1263             super(Image,self).reload()
   1264             if self.retina:
   1265                 self._retina_shape()

/usr/lib/python3.10/site-packages/IPython/core/display.py in reload(self)
    665             # Deferred import
    666             from urllib.request import urlopen
--> 667             response = urlopen(self.url)
    668             data = response.read()
    669             # extract encoding from header, if there is one:

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

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

/usr/lib64/python3.10/urllib/request.py in _open(self, req, data)
    534
    535         protocol = req.type
--> 536         result = self._call_chain(self.handle_open, protocol, protocol +
    537                                   '_open', req)
    538         if result:

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

/usr/lib64/python3.10/urllib/request.py in https_open(self, req)
   1389
   1390         def https_open(self, req):
-> 1391             return self.do_open(http.client.HTTPSConnection, req,
   1392                 context=self._context, check_hostname=self._check_hostname)
   1393

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

URLError: <urlopen error [Errno -3] Temporary failure in name resolution>