Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Computation and notebooks

This page contains example content for previewing or demonstrating computational content and notebooks, as well as Thebe integration.

Pandas

The following cell shows the output of a scrollable table.

Loading...

Matplotlib

<Figure size 1000x600 with 1 Axes>

Plotly

Loading...

Altair

Loading...

Bokeh

Loading...
Loading...
Loading...
Loading...

Text outputs

A simple cell with printed text output for comparison with error outputs below:

Hello, world!
Result: 5

A simple cell with ANSI codes, such as color, emphasis, etc. This uses a restricted palette, which is designed for maximum readability at the expense of styling richness. For example, dim and bright styles are disabled, and only foreground colours are used. Background colours are remapped to the foreground:

Everyone with telekinetic powers, raise my hand.. Dim
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep

there are separate styles for the stderr stream:

Everyone with telekinetic powers, raise my hand.. Dim
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep

We can also set the full-color-output class to show raw colors. Unlike the earlier example, raw colors include the full 8-bit ANSI palette, dim and bright styles, and both foreground and background colors:

Everyone with telekinetic powers, raise my hand.. Dim
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep

and the corresponding class full-color-error for stderr, too.

Everyone with telekinetic powers, raise my hand.. Dim
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep
Meep

Error outputs

You can use the raises-exception cell tag to indicate that a code cell is expected to error. This will display the error output but continue executing the rest of the notebook.

We use a semi-complex function with a traceback error to test out all the various types of error classes and make sure they show up properly:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[11], line 12
      8     def load(path: str, limit: int = 10) -> list:
      9         data = Path(path).read_text()
     10         return data.split("\n")[:limit]
     11 
---> 12 DataLoader.load(42)

Cell In[11], line 9, in DataLoader.load(path, limit)
      7     @staticmethod
      8     def load(path: str, limit: int = 10) -> list:
----> 9         data = Path(path).read_text()
     10         return data.split("\n")[:limit]

File ~/.local/share/mise/installs/python/3.12.13/lib/python3.12/pathlib.py:1162, in Path.__init__(self, *args, **kwargs)
   1159     msg = ("support for supplying keyword arguments to pathlib.PurePath "
   1160            "is deprecated and scheduled for removal in Python {remove}")
   1161     warnings._deprecated("pathlib.PurePath(**kwargs)", msg, remove=(3, 14))
-> 1162 super().__init__(*args)

File ~/.local/share/mise/installs/python/3.12.13/lib/python3.12/pathlib.py:373, in PurePath.__init__(self, *args)
    371             path = arg
    372         if not isinstance(path, str):
--> 373             raise TypeError(
    374                 "argument should be a str or an os.PathLike "
    375                 "object where __fspath__ returns a str, "
    376                 f"not {type(path).__name__!r}")
    377         paths.append(path)
    378 self._raw_paths = paths

TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'int'

We can also set the full-color-error class to show raw colours:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[12], line 12
      8     def load(path: str, limit: int = 10) -> list:
      9         data = Path(path).read_text()
     10         return data.split("\n")[:limit]
     11 
---> 12 DataLoader.load(42)

Cell In[12], line 9, in DataLoader.load(path, limit)
      7     @staticmethod
      8     def load(path: str, limit: int = 10) -> list:
----> 9         data = Path(path).read_text()
     10         return data.split("\n")[:limit]

File ~/.local/share/mise/installs/python/3.12.13/lib/python3.12/pathlib.py:1162, in Path.__init__(self, *args, **kwargs)
   1159     msg = ("support for supplying keyword arguments to pathlib.PurePath "
   1160            "is deprecated and scheduled for removal in Python {remove}")
   1161     warnings._deprecated("pathlib.PurePath(**kwargs)", msg, remove=(3, 14))
-> 1162 super().__init__(*args)

File ~/.local/share/mise/installs/python/3.12.13/lib/python3.12/pathlib.py:373, in PurePath.__init__(self, *args)
    371             path = arg
    372         if not isinstance(path, str):
--> 373             raise TypeError(
    374                 "argument should be a str or an os.PathLike "
    375                 "object where __fspath__ returns a str, "
    376                 f"not {type(path).__name__!r}")
    377         paths.append(path)
    378 self._raw_paths = paths

TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'int'

Embedding a full-color cell loses the annotation:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[12], line 12
      8     def load(path: str, limit: int = 10) -> list:
      9         data = Path(path).read_text()
     10         return data.split("\n")[:limit]
     11 
---> 12 DataLoader.load(42)

Cell In[12], line 9, in DataLoader.load(path, limit)
      7     @staticmethod
      8     def load(path: str, limit: int = 10) -> list:
----> 9         data = Path(path).read_text()
     10         return data.split("\n")[:limit]

File ~/.local/share/mise/installs/python/3.12.13/lib/python3.12/pathlib.py:1162, in Path.__init__(self, *args, **kwargs)
   1159     msg = ("support for supplying keyword arguments to pathlib.PurePath "
   1160            "is deprecated and scheduled for removal in Python {remove}")
   1161     warnings._deprecated("pathlib.PurePath(**kwargs)", msg, remove=(3, 14))
-> 1162 super().__init__(*args)

File ~/.local/share/mise/installs/python/3.12.13/lib/python3.12/pathlib.py:373, in PurePath.__init__(self, *args)
    371             path = arg
    372         if not isinstance(path, str):
--> 373             raise TypeError(
    374                 "argument should be a str or an os.PathLike "
    375                 "object where __fspath__ returns a str, "
    376                 f"not {type(path).__name__!r}")
    377         paths.append(path)
    378 self._raw_paths = paths

TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'int'

But we can restore it with a full-color-error class in a wrapping div or figure.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[12], line 12
      8     def load(path: str, limit: int = 10) -> list:
      9         data = Path(path).read_text()
     10         return data.split("\n")[:limit]
     11 
---> 12 DataLoader.load(42)

Cell In[12], line 9, in DataLoader.load(path, limit)
      7     @staticmethod
      8     def load(path: str, limit: int = 10) -> list:
----> 9         data = Path(path).read_text()
     10         return data.split("\n")[:limit]

File ~/.local/share/mise/installs/python/3.12.13/lib/python3.12/pathlib.py:1162, in Path.__init__(self, *args, **kwargs)
   1159     msg = ("support for supplying keyword arguments to pathlib.PurePath "
   1160            "is deprecated and scheduled for removal in Python {remove}")
   1161     warnings._deprecated("pathlib.PurePath(**kwargs)", msg, remove=(3, 14))
-> 1162 super().__init__(*args)

File ~/.local/share/mise/installs/python/3.12.13/lib/python3.12/pathlib.py:373, in PurePath.__init__(self, *args)
    371             path = arg
    372         if not isinstance(path, str):
--> 373             raise TypeError(
    374                 "argument should be a str or an os.PathLike "
    375                 "object where __fspath__ returns a str, "
    376                 f"not {type(path).__name__!r}")
    377         paths.append(path)
    378 self._raw_paths = paths

TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'int'

Wide cell inputs and outputs

These cells produce wide outputs to test that scrollable regions are keyboard-accessible (tab to focus, arrow keys to scroll).

MyST is really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really neat!

Multiple outputs

Loading...
Loading...