This page was generated from
doc/gallery/multiple-outputs.ipynb.
Interactive online version:
.
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!
---------------------------------------------------------------------------
gaierror Traceback (most recent call last)
File /usr/lib64/python3.14/urllib/request.py:1321, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
1320 try:
-> 1321 h.request(req.get_method(), req.selector, req.data, headers,
1322 encode_chunked=req.has_header('Transfer-encoding'))
1323 except OSError as err: # timeout error
File /usr/lib64/python3.14/http/client.py:1358, in HTTPConnection.request(self, method, url, body, headers, encode_chunked)
1357 """Send a complete request to the server."""
-> 1358 self._send_request(method, url, body, headers, encode_chunked)
File /usr/lib64/python3.14/http/client.py:1404, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked)
1403 body = _encode(body, 'body')
-> 1404 self.endheaders(body, encode_chunked=encode_chunked)
File /usr/lib64/python3.14/http/client.py:1353, in HTTPConnection.endheaders(self, message_body, encode_chunked)
1352 raise CannotSendHeader()
-> 1353 self._send_output(message_body, encode_chunked=encode_chunked)
File /usr/lib64/python3.14/http/client.py:1113, in HTTPConnection._send_output(self, message_body, encode_chunked)
1112 del self._buffer[:]
-> 1113 self.send(msg)
1115 if message_body is not None:
1116
1117 # create a consistent interface to message_body
File /usr/lib64/python3.14/http/client.py:1057, in HTTPConnection.send(self, data)
1056 if self.auto_open:
-> 1057 self.connect()
1058 else:
File /usr/lib64/python3.14/http/client.py:1492, in HTTPSConnection.connect(self)
1490 "Connect to a host on a given (SSL) port."
-> 1492 super().connect()
1494 if self._tunnel_host:
File /usr/lib64/python3.14/http/client.py:1023, in HTTPConnection.connect(self)
1022 sys.audit("http.client.connect", self, self.host, self.port)
-> 1023 self.sock = self._create_connection(
1024 (self.host,self.port), self.timeout, self.source_address)
1025 # Might fail in OSs that don't implement TCP_NODELAY
File /usr/lib64/python3.14/socket.py:846, in create_connection(address, timeout, source_address, all_errors)
845 exceptions = []
--> 846 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
847 af, socktype, proto, canonname, sa = res
File /usr/lib64/python3.14/socket.py:983, in getaddrinfo(host, port, family, type, proto, flags)
982 addrlist = []
--> 983 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
984 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.14/site-packages/IPython/core/display.py:1025, in Image.__init__(self, data, url, filename, format, embed, width, height, retina, unconfined, metadata, alt)
1023 self.unconfined = unconfined
1024 self.alt = alt
-> 1025 super(Image, self).__init__(data=data, url=url, filename=filename,
1026 metadata=metadata)
1028 if self.width is None and self.metadata.get('width', {}):
1029 self.width = metadata['width']
File /usr/lib/python3.14/site-packages/IPython/core/display.py:343, in DisplayObject.__init__(self, data, url, filename, metadata)
340 elif self.metadata is None:
341 self.metadata = {}
--> 343 self.reload()
344 self._check_data()
File /usr/lib/python3.14/site-packages/IPython/core/display.py:1060, in Image.reload(self)
1058 """Reload the raw data from file or URL."""
1059 if self.embed:
-> 1060 super(Image,self).reload()
1061 if self.retina:
1062 self._retina_shape()
File /usr/lib/python3.14/site-packages/IPython/core/display.py:374, in DisplayObject.reload(self)
371 elif self.url is not None:
372 # Deferred import
373 from urllib.request import urlopen
--> 374 response = urlopen(self.url)
375 data = response.read()
376 # extract encoding from header, if there is one:
File /usr/lib64/python3.14/urllib/request.py:187, in urlopen(url, data, timeout, context)
185 else:
186 opener = _opener
--> 187 return opener.open(url, data, timeout)
File /usr/lib64/python3.14/urllib/request.py:487, in OpenerDirector.open(self, fullurl, data, timeout)
484 req = meth(req)
486 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 487 response = self._open(req, data)
489 # post-process response
490 meth_name = protocol+"_response"
File /usr/lib64/python3.14/urllib/request.py:504, in OpenerDirector._open(self, req, data)
501 return result
503 protocol = req.type
--> 504 result = self._call_chain(self.handle_open, protocol, protocol +
505 '_open', req)
506 if result:
507 return result
File /usr/lib64/python3.14/urllib/request.py:464, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
462 for handler in handlers:
463 func = getattr(handler, meth_name)
--> 464 result = func(*args)
465 if result is not None:
466 return result
File /usr/lib64/python3.14/urllib/request.py:1369, in HTTPSHandler.https_open(self, req)
1368 def https_open(self, req):
-> 1369 return self.do_open(http.client.HTTPSConnection, req,
1370 context=self._context)
File /usr/lib64/python3.14/urllib/request.py:1324, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
1321 h.request(req.get_method(), req.selector, req.data, headers,
1322 encode_chunked=req.has_header('Transfer-encoding'))
1323 except OSError as err: # timeout error
-> 1324 raise URLError(err)
1325 r = h.getresponse()
1326 except:
URLError: <urlopen error [Errno -3] Temporary failure in name resolution>