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

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/homepage/main-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)
File /usr/lib/python3.12/urllib/request.py:1344, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
   1343 try:
-> 1344     h.request(req.get_method(), req.selector, req.data, headers,
   1345               encode_chunked=req.has_header('Transfer-encoding'))
   1346 except OSError as err: # timeout error

File /usr/lib/python3.12/http/client.py:1336, in HTTPConnection.request(self, method, url, body, headers, encode_chunked)
   1335 """Send a complete request to the server."""
-> 1336 self._send_request(method, url, body, headers, encode_chunked)

File /usr/lib/python3.12/http/client.py:1382, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked)
   1381     body = _encode(body, 'body')
-> 1382 self.endheaders(body, encode_chunked=encode_chunked)

File /usr/lib/python3.12/http/client.py:1331, in HTTPConnection.endheaders(self, message_body, encode_chunked)
   1330     raise CannotSendHeader()
-> 1331 self._send_output(message_body, encode_chunked=encode_chunked)

File /usr/lib/python3.12/http/client.py:1091, in HTTPConnection._send_output(self, message_body, encode_chunked)
   1090 del self._buffer[:]
-> 1091 self.send(msg)
   1093 if message_body is not None:
   1094
   1095     # create a consistent interface to message_body

File /usr/lib/python3.12/http/client.py:1035, in HTTPConnection.send(self, data)
   1034 if self.auto_open:
-> 1035     self.connect()
   1036 else:

File /usr/lib/python3.12/http/client.py:1470, in HTTPSConnection.connect(self)
   1468 "Connect to a host on a given (SSL) port."
-> 1470 super().connect()
   1472 if self._tunnel_host:

File /usr/lib/python3.12/http/client.py:1001, in HTTPConnection.connect(self)
   1000 sys.audit("http.client.connect", self, self.host, self.port)
-> 1001 self.sock = self._create_connection(
   1002     (self.host,self.port), self.timeout, self.source_address)
   1003 # Might fail in OSs that don't implement TCP_NODELAY

File /usr/lib/python3.12/socket.py:841, in create_connection(address, timeout, source_address, all_errors)
    840 exceptions = []
--> 841 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    842     af, socktype, proto, canonname, sa = res

File /usr/lib/python3.12/socket.py:976, in getaddrinfo(host, port, family, type, proto, flags)
    975 addrlist = []
--> 976 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    977     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)
Cell In[1], line 6
      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))

File /usr/lib/python3/dist-packages/IPython/core/display.py:1050, in Image.__init__(self, data, url, filename, format, embed, width, height, retina, unconfined, metadata, alt)
   1048 self.unconfined = unconfined
   1049 self.alt = alt
-> 1050 super(Image, self).__init__(data=data, url=url, filename=filename,
   1051         metadata=metadata)
   1053 if self.width is None and self.metadata.get('width', {}):
   1054     self.width = metadata['width']

File /usr/lib/python3/dist-packages/IPython/core/display.py:370, in DisplayObject.__init__(self, data, url, filename, metadata)
    367 elif self.metadata is None:
    368     self.metadata = {}
--> 370 self.reload()
    371 self._check_data()

File /usr/lib/python3/dist-packages/IPython/core/display.py:1085, in Image.reload(self)
   1083 """Reload the raw data from file or URL."""
   1084 if self.embed:
-> 1085     super(Image,self).reload()
   1086     if self.retina:
   1087         self._retina_shape()

File /usr/lib/python3/dist-packages/IPython/core/display.py:401, in DisplayObject.reload(self)
    398 elif self.url is not None:
    399     # Deferred import
    400     from urllib.request import urlopen
--> 401     response = urlopen(self.url)
    402     data = response.read()
    403     # extract encoding from header, if there is one:

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

File /usr/lib/python3.12/urllib/request.py:515, in OpenerDirector.open(self, fullurl, data, timeout)
    512     req = meth(req)
    514 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 515 response = self._open(req, data)
    517 # post-process response
    518 meth_name = protocol+"_response"

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

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

File /usr/lib/python3.12/urllib/request.py:1392, in HTTPSHandler.https_open(self, req)
   1391 def https_open(self, req):
-> 1392     return self.do_open(http.client.HTTPSConnection, req,
   1393                         context=self._context)

File /usr/lib/python3.12/urllib/request.py:1347, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
   1344         h.request(req.get_method(), req.selector, req.data, headers,
   1345                   encode_chunked=req.has_header('Transfer-encoding'))
   1346     except OSError as err: # timeout error
-> 1347         raise URLError(err)
   1348     r = h.getresponse()
   1349 except:

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