GRASS Jupyter currently returns an IPython.displayImage object when displaying a map image with a Jupyter notebook. As shown here.
def show(self):
"""Displays a PNG image of map"""
# Lazy import to avoid an import-time dependency on IPython.
from IPython.display import Image # pylint: disable=import-outside-toplevel
return Image(self._filename)
This is fine for many use cases but does not work when the image needs to be displayed inline with various Jupyter frontends (JupyterHub, Colab, VSCode, etc..). My specific use-case is using quarto (.qmd) to create figure layouts with VSCode that are rendered to html, pdf, or latex formats. Using the the current grass.jupyter api, you are unable to use the layout functionality of quarto without calling map.show() within the IPython.displaydisplay function like display(map.show().
To address this we should use the IPython.displaydisplay function to display the map image so that we let the Jupyter frontends decide which representation is used and how.
def show(self):
"""Displays a PNG image of map"""
# Lazy import to avoid an import-time dependency on IPython.
from IPython.display import Image, display # pylint: disable=import-outside-toplevel
display(Image(self._filename))
GRASS Jupyter currently returns an
IPython.display
Image
object when displaying a map image with a Jupyter notebook. As shown here.This is fine for many use cases but does not work when the image needs to be displayed inline with various Jupyter frontends (JupyterHub, Colab, VSCode, etc..). My specific use-case is using quarto (.qmd) to create figure layouts with VSCode that are rendered to html, pdf, or latex formats. Using the the current
grass.jupyter api
, you are unable to use the layout functionality of quarto without callingmap.show()
within theIPython.display
display
function likedisplay(map.show()
.Example using quarto layouts
To address this we should use the
IPython.display
display
function to display the map image so that we let the Jupyter frontends decide which representation is used and how.Read more here: https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.display