Features#
Flexible FILE
argument#
nbpreview has only one required argument—FILE
—which
expects a Jupyter notebook (.ipynb
) file path.
% nbpreview notebook.ipynb
FILE
is a flexible argument.
It can take in multiple files
and render them all at once.
nbpreview will accept multiple file paths manually listed out,
% nbpreview notebook1.ipynb notebook2.ipynb
or a glob that expands to one or more notebook files.
% nbpreview notebooks/*.ipynb
FILE
also accepts text from stdin
and treats it as the contents of a notebook file.
This can be used to easily view notebooks from the web1 using curl2.
% curl https://raw.githubusercontent.com/paw-lu/nbpreview/main/tests/unit/assets/notebook.ipynb | nbpreview
This can even be used to filter cells before rendering them. For example, jq3 can be used to select only the markdown cells from a notebook. These cells are then passed on to nbpreview to render.
% jq 'with_entries(if .key == "cells" then .value |= map(select(.cell_type == "markdown")) else . end)' tests/unit/assets/notebook.ipynb | nbp
Smart output#
Automatic plain output#
nbpreview is smart about its output.
By default it will strip out decorations—such
as boxes, execution counts, and extra spacing—when
its output is piped to stdout.
This makes nbpreview usable as a preprocessor for other command-line tools.
For example,
if fgrep4 is used to search a notebook file for the string 'parietal'
,
the output can be difficult to parse.
% fgrep parietal notebook.ipynb
" <td>parietal</td>\n",
" <td>parietal</td>\n",
" <td>parietal</td>\n",
" <td>parietal</td>\n",
" <td>parietal</td>\n",
"0 s13 18 stim parietal -0.017552\n",
"1 s5 14 stim parietal -0.080883\n",
"2 s12 18 stim parietal -0.081033\n",
"3 s11 18 stim parietal -0.046134\n",
"4 s10 18 stim parietal -0.037970"
Instead, if the notebook is run through nbpreview first, it will process the file before passing it onto fgrep, creating a more human-readable output.
% nbpreview notebook.ipynb | fgrep parietal
0 s13 18 stim parietal -0.017552
1 s5 14 stim parietal -0.080883
2 s12 18 stim parietal -0.081033
3 s11 18 stim parietal -0.046134
4 s10 18 stim parietal -0.037970
Plain rendering can be manually forced
by using the --plain
(or -p
)
option,
% nbpreview --plain notebook.ipynb
or completely disabled
by using the --decorated
(or -d
)
option.
% nbpreview --decorated notebook.ipynb
This can be configured by setting the NBPREVIEW_PLAIN environmental variable. For example, to set the default rendering to be plain, run:
% export NBPREVIEW_PLAIN=1
Automatic paging#
nbpreview will automatically view the output in a pager if the output is longer than the terminal—which is often. Similar to the automatic plain output, this will be automatically disabled when piping to other commands.
Thanks to Click
,
nbpreview attempts to choose a pager that renders the notebook in color.
If the PAGER
environmental variable is set,
nbpreview will use the value as the pager command.
To disable the automatic paging,
use the --no-paging
(or -f
) option.
% nbpreview --no-paging notebook.ipynb
Conversely,
to manually force paging,
use the --paging
(or -g
)
option.
This can be configured by setting
the NBPREVIEW_PAGING environmental variable.
Syntax highlighting#
Themes#
Thanks to Pygments and Rich
,
nbpreview comes with many different syntax highlighting themes.
They can be applied using the --theme
(or -t
)
option.
Some themes may clash with the terminal theme,
but 'dark'
—the
default theme—and
'light'
will match the terminal’s colors.
% nbpreview --theme material notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[ ]: │ from typing import Iterator │
│ │
│ │
│ class Math: │
│ """An example class.""" │
│ │
│ @staticmethod │
│ def fib(n: int) -> Iterator[int]: │
│ """Fibonacci series up to n.""" │
│ a, b = 0, 1 # Manually set first two terms │
│ while a < n: │
│ yield a │
│ a, b = b, a + b │
│ │
│ │
│ result = sum(Math.fib(42)) │
│ print(f"The answer is {result}") │
╰────────────────────────────────────────────────────────────────────────╯
% nbpreview --theme dracula notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[ ]: │ from typing import Iterator │
│ │
│ │
│ class Math: │
│ """An example class.""" │
│ │
│ @staticmethod │
│ def fib(n: int) -> Iterator[int]: │
│ """Fibonacci series up to n.""" │
│ a, b = 0, 1 # Manually set first two terms │
│ while a < n: │
│ yield a │
│ a, b = b, a + b │
│ │
│ │
│ result = sum(Math.fib(42)) │
│ print(f"The answer is {result}") │
╰────────────────────────────────────────────────────────────────────────╯
% nbpreview --theme one-dark notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[ ]: │ from typing import Iterator │
│ │
│ │
│ class Math: │
│ """An example class.""" │
│ │
│ @staticmethod │
│ def fib(n: int) -> Iterator[int]: │
│ """Fibonacci series up to n.""" │
│ a, b = 0, 1 # Manually set first two terms │
│ while a < n: │
│ yield a │
│ a, b = b, a + b │
│ │
│ │
│ result = sum(Math.fib(42)) │
│ print(f"The answer is {result}") │
╰────────────────────────────────────────────────────────────────────────╯
% nbpreview --theme monokai notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[ ]: │ from typing import Iterator │
│ │
│ │
│ class Math: │
│ """An example class.""" │
│ │
│ @staticmethod │
│ def fib(n: int) -> Iterator[int]: │
│ """Fibonacci series up to n.""" │
│ a, b = 0, 1 # Manually set first two terms │
│ while a < n: │
│ yield a │
│ a, b = b, a + b │
│ │
│ │
│ result = sum(Math.fib(42)) │
│ print(f"The answer is {result}") │
╰────────────────────────────────────────────────────────────────────────╯
% nbpreview --theme paraiso-light notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[ ]: │ from typing import Iterator │
│ │
│ │
│ class Math: │
│ """An example class.""" │
│ │
│ @staticmethod │
│ def fib(n: int) -> Iterator[int]: │
│ """Fibonacci series up to n.""" │
│ a, b = 0, 1 # Manually set first two terms │
│ while a < n: │
│ yield a │
│ a, b = b, a + b │
│ │
│ │
│ result = sum(Math.fib(42)) │
│ print(f"The answer is {result}") │
╰────────────────────────────────────────────────────────────────────────╯
% nbpreview --theme rainbow_dash notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[ ]: │ from typing import Iterator │
│ │
│ │
│ class Math: │
│ """An example class.""" │
│ │
│ @staticmethod │
│ def fib(n: int) -> Iterator[int]: │
│ """Fibonacci series up to n.""" │
│ a, b = 0, 1 # Manually set first two terms │
│ while a < n: │
│ yield a │
│ a, b = b, a + b │
│ │
│ │
│ result = sum(Math.fib(42)) │
│ print(f"The answer is {result}") │
╰────────────────────────────────────────────────────────────────────────╯
For a list of all available themes
along with a preview of how they look on the terminal
use the --list-themes
option.
% nbpreview --list-themes
Cell magic#
Certain cell magics may be used to run other languages in a Jupyter Notebook cell.
nbpreview detects the use of these magic commands
and adjusts its syntax highlighting to match it.
For example,
here it switches to bash syntax highlighting when the %%bash
cell magic is used.
% nbpreview --theme material notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[ ]: │ %%bash │
│ for file in *.csv; do │
│ echo "$file" │
│ awk -F ',' '{print $5}' "$file" | sort | uniq -c │
│ done │
╰────────────────────────────────────────────────────────────────────────╯
Multi-language support#
Jupyter Notebooks are not Python exclusive. nbpreview will detect the usage of other languages—such as Julia.
% nbpreview --theme material notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[2]: │ function printx(x) │
│ println("x = $x") │
│ return nothing │
│ end │
╰────────────────────────────────────────────────────────────────────────╯
Wrapping and line numbers#
Depending on your terminal size,
code cell contents might be too long to fit on the terminal.
By default,
nbpreview truncates the long code.
But if --code-wrap
(or -q
)
is used,
nbpreview will wrap the code around so that it’s all visible.
It’s usually best to use this will --line-numbers
(or -m
)
to enable line numbers—so
that wrapping is clearly distinguished from a line break.
% nbpreview --theme material --code-wrap --line-numbers notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[5]: │ 1 ( │
│ 2 df.loc[lambda _df: (_df["sepal.length"] < 6.0) & │
│ (_df["petal.length"] < 3.5)] │
│ 3 .groupby("variety")["petal.width"] │
│ 4 .mean() │
│ 5 ) │
╰────────────────────────────────────────────────────────────────────────╯
Markdown rendering#
Thanks to Rich
,
markdown-it-py,
and pylatexenc,
nbpreview renders markdown content with some extensions.
In addition to typical CommonMark,
nbpreview will also render markdown tables,
create clickable hyperlinks
(if it’s supported by the terminal),
syntax highlight code blocks
(which respect --theme
),
and render block math equations.
It will even render images—which
respect --image-drawing
.
For example,
# Lorem ipsum
Lorem ipsum dolor sit amet,
consectetur **adipiscing** elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna [aliqua](https://github.com/paw-lu/nbpreview).
$$
\alpha \sim \text{Normal(0, 1)}
$$
_Ut enim ad minim veniam_,
quis nostrud exercitation ullamco
Excepteur sint occaecat `cupidatat` non proident,
sunt in culpa qui.

## At ultrices
```python
def add(x: float, y: float) -> float:
"""Add two numbers."""
return x + y
```
| Lorep | ipsum | doret |
| ----- | ----- | ----- |
| 1 | 2 | 3 |
| 4 | 5 | 6 |
renders as
% nbpreview --theme material --image-drawing character notebook.ipynb
Lorem ipsum
─────────────────────────────────────────────────────────────────────────────
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
α∼Normal(0, 1)
Ut enim ad minim veniam, quis nostrud exercitation ullamco Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui.
🖼 Click to view Turtle
?????????????????
?????????????????????????PP
P??????????????????????????PPP???
?PPPPP????????????????????PPPPPPP??????
???PPPPPPPPPPPP??????PPPPPPPP????PPP?????
????PPP?????PPPPPPPPPPPPPP??????????PPPP?????
::!??PPPP??????????????PPPP??????????????PPP?????
!!!!!!!!!!!!!!!!???????????????PPP???????????????PPPP???P!
!!!!!!!!!!!!!!!!!!!!!????????????PPPP????????????????PPPP?PP !!
!!!!!!!!!!!!!!!!!!!!!!!!!???????????PPP?????????????????PPPPPP?!!!!!
:!!!!GGGG!!!!!!!PGG!!!!!!!!!??????????PPP??????????????????PPPP??!!!!
:!!!!GGGGGG!!!!!GGGGGG!!!!!!!!??????????PPP?????????????????PPP???!!:
!!!!!!GGGG!!!!!!!GGGGG!!!!!!!!!?????????PPP???????????????PPPP???!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!??????????PPP???????????PPPPP????!:
!!!!!!!!GGG!!!!!GG!!!!!!!!!!!!!!?????????PPP??????PPPPPPP??????!!
!!!!!!!!!GGGGGG!!!!!!!!!!!!!!!!?PPPPPPPPPPPPPPPPPPPPP???????!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!???PPPPPPP??????????????!!!!!!!!
:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!???????????????????!!!!!!!!!!!!:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :::
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!! !!!!!!!!!!!!:
!!!!!!!!!!!! !!!!!!!!!!!!!
!!!!!!!!!!! !!!!!!!!!!!!!
!!!!!!!!!!!!
!!!!!!!
## At ultrices
─────────────────────────────────────────────────────────────────────────────
def add(x: float, y: float) -> float:
"""Add two numbers."""
return x + y
Lorep ipsum doret
─────────────────────────────────────────────────────────────────────────────
1 2 3
4 5 6
Images#
Thanks to Picharsso
and term-image
,
nbpreview renders images.
Drawing types#
The --image-drawing
(or --id
)
option can be used to control the method nbpreview uses to draw images.
% nbpreview --theme material --image-drawing block notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[4]: │ ( │
│ sns.load_dataset("penguins").pipe( │
│ (sns.kdeplot, "data"), │
│ x="flipper_length_mm", │
│ hue="species", │
│ multiple="stack", │
│ ) │
│ ) │
╰────────────────────────────────────────────────────────────────────────╯
[4]: <AxesSubplot:xlabel='flipper_length_mm', ylabel='Density'>
🖼 Click to view Image
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀ ▀ ▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀ ▀▀
▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀
▄▄▄▄▄ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀ ▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀
▀▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀
▀▀ ▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀▀
▄ ▄ ▄▄▄ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀ ▀▀▀ ▀▀▀ ▀▀▀▀ ▀▀▀▀
▀▀ ▀▄▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀ ▀▀▀ ▀▀▀▀ ▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀ ▀▀▀▀▀▀
▄▄▄▄▄ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀ ▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀
▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄
▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀
▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄
▀▀▀▀ ▀▀ ▀▀ ▀
% nbpreview --theme material --image-drawing character notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[4]: │ ( │
│ sns.load_dataset("penguins").pipe( │
│ (sns.kdeplot, "data"), │
│ x="flipper_length_mm", │
│ hue="species", │
│ multiple="stack", │
│ ) │
│ ) │
╰────────────────────────────────────────────────────────────────────────╯
[4]: <AxesSubplot:xlabel='flipper_length_mm', ylabel='Density'>
🖼 Click to view Image
!? PP
PPP
?! PPPPP
:PPPPP G!!!! : !! :!
PPPPPPP
PPPPPPP
PPPPPPPPP
? PPPPPPPPP P?!!
PPPPPPPPPPP PP!!!!
? ? PPPPPPPPPPP PP!!!!!!
PPPPPPPPPPPPP !!!!!!!!!
PPPPPPPPPPPPPP P!!!!!!!!!G
PPPPPPPG!!!!!PPP!!!!!!!!!!!P
PPPPPPP!!!!!!!!!!?!!!!!!!!!!!!!G
?: PPPPPP?!!!!!!!!!!!!!!!!!!!!!!!!!!P
PPPPPG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!G
!?: PPPPP!!!!!!!!!!!!!!P!!!!!!!!!!!!!!!!!!!!!G
:: :: : :: ??
:
% nbpreview --theme material --image-drawing braille notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[4]: │ ( │
│ sns.load_dataset("penguins").pipe( │
│ (sns.kdeplot, "data"), │
│ x="flipper_length_mm", │
│ hue="species", │
│ multiple="stack", │
│ ) │
│ ) │
╰────────────────────────────────────────────────────────────────────────╯
[4]: <AxesSubplot:xlabel='flipper_length_mm', ylabel='Density'>
🖼 Click to view Image
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣛⣛⣛⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣍⡻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣯⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣼⣿⣿⣿⣿⣿⣿⣿⣷⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣟⣿⣿⣿⣿⣿⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣾⣿⣿⣿⣿⣿⣿⣿⡾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣞⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣯⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣞⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢟⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⢿⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣝⢿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
Negative and positive space#
By default,
nbpreview draws figures in negative space—meaning
characters are used to draw the dark portions of the image.
This works well as a default since most charts have a light background by default.
However, when working with darker images—like
if a dark theme is being used on a plot—the
drawing can be switched to positive space
using the --positive-space
(or -s
)
option.
Attention
--positive-space
only works on --image-drawing='character'
.
--image-drawing='braille'
only draws in positive space.
% nbpreview --theme material --image-drawing character --positive-space
notebook.ipynb
╭───────────────────────────────────────────────────────────────────────╮
[17]: │ _, ax = plt.subplots(facecolor="#1C1B1F") │
│ ( │
│ sns.load_dataset("fmri").pipe( │
│ (sns.lineplot, "data"), │
│ x="timepoint", │
│ y="signal", │
│ hue="region", │
│ alpha=1, │
│ ax=ax, │
│ ) │
│ ) │
╰───────────────────────────────────────────────────────────────────────╯
[17]: <AxesSubplot:xlabel='timepoint', ylabel='signal'>
🖼 Click to view Image
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::!::!:::::::::::::::::::::::::::::::::::::
:::::::::::?:::::::::::::::::::::::!::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::G::G::::::::::::::::::G:::G::!:::::::::::::::::::????:::G?:!::::
:::::::::::::::::::::::::::::G!!!!!G::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::!G!!::!!!G:::::::::::::::::::::::::::::::::::
:::::::::::?:::::::::::::::!!!P::?:!!G:!::::::::::::::::::::::::::::::::
::!::::::::::::::::::::::::!P::::::?!!P:::::::::::::::::::::::::::::::::
::!::::::::::::::::::::::!GP::::::::P!::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::GP::::::::!:P!:::::::::::::::::::::::::::::::::
::::::::::::::::::::::::G!::::::::::::P!::!:::::::::::::::::::::::::::::
::::::::::G!::::::!::!:P!::::::::::::::P!!!!::::::::::::::::::!!!:::::::
:::::::::::::::::!!!!!!!:::::::::::::::::!!::::::::::::!P::!!!!!!!!!::::
:::::::::::::::::::!!:::::::::::::::::::::P!G!!!:!P:!!!!:?P:::::::::::::
::::::::::::::::::::::::::::::::::::::::::!:!!??!!!:PP::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::!::::::::::::::::::
:::::::G:::?::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::!:::::!:G::::?:!:::::::::::!?P::::G::P::::::P::::P:!:::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::!:::::::::::::::::::::::::::::
% nbpreview --theme material --image-drawing character notebook.ipynb
╭───────────────────────────────────────────────────────────────────────╮
[17]: │ _, ax = plt.subplots(facecolor="#1C1B1F") │
│ ( │
│ sns.load_dataset("fmri").pipe( │
│ (sns.lineplot, "data"), │
│ x="timepoint", │
│ y="signal", │
│ hue="region", │
│ alpha=1, │
│ ax=ax, │
│ ) │
│ ) │
╰───────────────────────────────────────────────────────────────────────╯
[17]: <AxesSubplot:xlabel='timepoint', ylabel='signal'>
🖼 Click to view Image
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGPGGPGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGG?GGGGGGGGGGGGGGGGGGGGGGGPGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGG:GG:GGGGGGGGGGGGGGGGGG:GGG:GGPGGGGGGGGGGGGGGGGGGG????GGG:?GPGGGG
GGGGGGGGGGGGGGGGGGGGGGGGGGGGG:PPPPP:GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGGGGGGGGGP:PPGGPPP:GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGG?GGGGGGGGGGGGGGGPPP!GG?GPP:GPGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGPGGGGGGGGGGGGGGGGGGGGGGGGP!GGGGGG?PP!GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGPGGGGGGGGGGGGGGGGGGGGGGP:!GGGGGGGG!PGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGGGGGGG:!GGGGGGGGPG!PGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGGGGGG:PGGGGGGGGGGGG!PGGPGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGG:PGGGGGGPGGPG!PGGGGGGGGGGGGGG!PPPPGGGGGGGGGGGGGGGGGGPPPGGGGGGG
GGGGGGGGGGGGGGGGGPPPPPPPGGGGGGGGGGGGGGGGGPPGGGGGGGGGGGGP!GGPPPPPPPPPGGGG
GGGGGGGGGGGGGGGGGGGPPGGGGGGGGGGGGGGGGGGGGG!P:PPPGP!GPPPPG?!GGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGPGPP??PPPG!!GGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGPGGGGGGGGGGGGGGGGGG
GGGGGGG:GGG?GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGPGGGGGPG:GGGG?GPGGGGGGGGGGGP?!GGGG:GG!GGGGGG!GGGG!GPGGG
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGPGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
% nbpreview --theme material --image-drawing braille notebook.ipynb
╭───────────────────────────────────────────────────────────────────────╮
[17]: │ _, ax = plt.subplots(facecolor="#1C1B1F") │
│ ( │
│ sns.load_dataset("fmri").pipe( │
│ (sns.lineplot, "data"), │
│ x="timepoint", │
│ y="signal", │
│ hue="region", │
│ alpha=1, │
│ ax=ax, │
│ ) │
│ ) │
╰───────────────────────────────────────────────────────────────────────╯
[17]: <AxesSubplot:xlabel='timepoint', ylabel='signal'>
🖼 Click to view Image
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠯⠈⠳⠁⠀⠀⠐⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⡒⠒⠒⠒⠒⢒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠚⠛⠛⠚⠒⠒⠒⠒⢒⠒⠒⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠒⠒⠒⠒⠀⢸⠽⠿⠑⠏⠽⠿⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠁⣰⠋⠙⠒⢆⠀⠀⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⠀⢠⡀⢀⢀⡄⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠓⠀⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠎⣹⣫⣿⣿⣯⡍⢏⠉⠉⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠁⠈⠈⠉⠁⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⣰⣷⣿⠿⢿⣿⣿⡘⢇⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⡤⠠⣤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣣⣿⣿⣫⠶⢤⣈⢻⣷⣌⣆⣀⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠉⠀⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡈⣾⣟⠝⠁⠀⠀⠈⢳⣻⣿⡼⡄⠐⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢨⣉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣹⣿⠋⠀⡠⠀⠄⠀⠀⢳⣿⣷⣹⡀⢡⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢸⣿⠃⠀⠀⠀⠀⣖⢰⡂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢦⣿⠇⡠⠊⠀⠀⠀⠀⠠⠀⠹⣿⣷⢧⠤⠆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣨⣿⡏⠄⠀⠀⠀⠀⠀⠀⠀⠁⠀⠹⣿⣯⢇⠈⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⡟⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠹⣿⣯⣆⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠯⠼⠝⠄⠀⠀⠀⠀⠀⠤⣀⣂⣐⣠⣭⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠹⣿⣿⣏⠑⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠠⠀⣀⣀⣒⣂⣀⣠⣤⠬⠭⠅⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠺⢷⣒⣷⠿⠋⠍⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢂⠘⢿⣿⣦⣌⡄⠀⢀⡀⠠⠐⠀⢉⣀⠤⢔⣒⣯⡭⠷⠶⢒⣒⣒⣒⣒⣒⣒⡂⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢄⢠⡄⡄⠀⠀⢀⣀⣀⣀⣁⣂⣅⣂⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣻⣿⣿⣿⣷⣦⣠⣴⣒⣯⣥⣶⣾⣛⣩⣴⣒⣋⣉⣉⣠⣤⣤⣄⣀⣀⣀⣀⣀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠈⠈⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠈⡻⣿⣿⣿⣿⣿⣿⡯⠵⠒⠋⠁⡀⠄⠂⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠐⠀⣀⣀⣀⡀⠠⠄⠂⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢰⠐⢰⠂⠀⠀⢠⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣖⢰⡂⠀⠀⠀⠀⡲⢰⡄⠀⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⢀⠂⣦⠀⠀⠀⠀⠂⢰⢰⡆⠀⠀⠀⠂⠐⢰⡄⠀⠀⠀⢲⣦⠀⠠⠀⠀⠀⢰⠠⠀⢠⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⠀⠶⢶⠶⠀⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
% nbpreview --theme material --image-drawing block notebook.ipynb
╭───────────────────────────────────────────────────────────────────────╮
[17]: │ _, ax = plt.subplots(facecolor="#1C1B1F") │
│ ( │
│ sns.load_dataset("fmri").pipe( │
│ (sns.lineplot, "data"), │
│ x="timepoint", │
│ y="signal", │
│ hue="region", │
│ alpha=1, │
│ ax=ax, │
│ ) │
│ ) │
╰───────────────────────────────────────────────────────────────────────╯
[17]: <AxesSubplot:xlabel='timepoint', ylabel='signal'>
🖼 Click to view Image
▀▀▀▀
▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀ ▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀ ▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀ ▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀ ▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀ ▀▀▀
▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀ ▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀▀ ▀▀▀▀▀▀ ▀▀▀▀▀ ▀▀▀▀▀▀
▀▀▀ ▀▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀
▀▀▀▀▀▀ ▀▀
▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Enabling and disabling image rendering#
By default,
nbpreview will attempt to detect
if images can be viewed on the terminal.
This can be manually controlled via the
--images
or --no-images
options.
Caution
Rendering images can impact nbpreview’s performance—especially
if the notebook contains many images.
The drawing type selected
via --image-drawing
can play a role in how severe the performance impact is.
DataFrame rendering#
Thanks to Rich
and lxml
,
nbpreview renders Pandas DataFrame as a table.
% nbpreview --theme material notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[2]: │ pd.DataFrame( │
│ [ │
│ [38.0, 2.0, 18.0, 22.0], │
│ [19, 439, 6, 452], │
│ ], │
│ index=pd.Index( │
│ ["Tumour (Positive)", "Non-Tumour (Negative)"], │
│ name="Actual Label:", │
│ ), │
│ columns=pd.MultiIndex.from_product( │
│ [["Decision Tree", "Regression"], ["Tumour", "Non-Tumour"]], │
│ names=["Model:", "Predicted:"], │
│ ), │
│ ) │
╰────────────────────────────────────────────────────────────────────────╯
[2]: 🌐 Click to view HTML
[2]: Model: Decision Tree Regression
Predicted: Tumour Non-Tumour Tumour Non-Tumour
Actual Label:
──────────────────────────────────────────────────────────────────────
Tumour (Positive) 38.0 2.0 18.0 22.0
Non-Tumour (Negative) 19.0 439.0 6.0 452.0
Vega and VegaLite charts#
nbpreview will renderer static previews of Vega and VegaLite charts along with a link to an interactive version (thanks to justcharts).
% nbpreview --theme material --image-drawing character notebook.ipynb
╭───────────────────────────────────────────────────────────────────────╮
[12]: │ VegaLite( │
│ { │
│ "$schema": "https://vega.github.io/schema/vega-lite/v5.json", │
│ "description": "Google's stock price over time.", │
│ "data": {"url": "https://raw.githubusercontent.com/vega/vega… │
│ "transform": [{"filter": "datum.symbol==='GOOG'"}], │
│ "mark": { │
│ "type": "area", │
│ "line": {"color": "darkgreen"}, │
│ "color": { │
│ "x1": 1, │
│ "y1": 1, │
│ "x2": 1, │
│ "y2": 0, │
│ "gradient": "linear", │
│ "stops": [ │
│ {"offset": 0, "color": "white"}, │
│ {"offset": 1, "color": "darkgreen"}, │
│ ], │
│ }, │
│ }, │
│ "encoding": { │
│ "x": {"field": "date", "type": "temporal"}, │
│ "y": {"field": "price", "type": "quantitative"}, │
│ }, │
│ } │
│ ) │
╰───────────────────────────────────────────────────────────────────────╯
📊 Click to view Vega chart
?? ?
?
?
? G
? P?P
? ??G
? !??P G
G PP ? G??? G ?P
? P??? G? ?? ?
? : !!!!? ?!! G!!P?
? P: ?!!!!!!G !!P !!!!!
? ?!!G:P!!!!!!!! !!!P P!!!!!
G ? : !!!!!!!!!!!!!!!!!!!P :!!!!!!!
@ P ?? ? P! GGP G!!!!!!!!!!!!!!!!!!!P !!!!!!!!!
! ? G!!G!!!!?!!!!!!!!!!!!!!!!!!!!!! P!!!!!!!!!
? ?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!G G!!!!!!!!!!
? G::::::::::::::::::::::::::::::::G::::::::::::
? GPG::::::::::::::::::::::::::::::::!:::::::::::::
? G:::::::::::::::::::::::::::::::::::::::::::::::::
? !:::::::::::::::::::::::::::::::::::::::::::::::::
P:!!:??:::P:P::::::::::::::::::::::::::::::::::::::::::::::::::
?::::::::::::::::::::::::::::::::::::::::::::::::::::::::
?G:::::::::::::::::::::::::::::::::::::::::::::::::::::::
G
:
:
:
P
?@ : P! : :?G: ! ?@ !G ?@ @? :! :
G!GP !
\(\LaTeX\)#
Thanks to pylatexenc
,
nbpreview can render \(\LaTeX\) as unicode characters.
% nbpreview --theme material notebook.ipynb
╭───────────────────────────────────────────────────────────────────────╮
[22]: │ with pm.Model() as model: │
│ alpha = pm.Normal("alpha", mu=0, sd=10) │
│ beta = pm.Normal("beta", mu=0, sd=1) │
│ epsilon = pm.HalfCauchy("epsilon", beta=5) │
│ │
│ mu = pm.Deterministic("mu", var=alpha + beta * x) │
│ y_pred = pm.Normal("y_pred", mu=mu, sd=epsilon, observed=y) │
│ y_pred │
╰───────────────────────────────────────────────────────────────────────╯
[22]: y_pred∼Normal(𝑚𝑢=mu, 𝑠𝑖𝑔𝑚𝑎=f(epsilon))
HTML#
Thanks to html2text, nbpreview renders basic HTML. It will also generate a link to the output so it can be easily previewed in the browser.
% nbpreview --theme material notebook.ipynb
╭───────────────────────────────────────────────────────────────────────╮
[15]: │ %%html │
│ <p> │
│ Lorem <em>ipsum</em> dolor sit amet, │
│ consectetur adipiscing elit, │
│ sed do eiusmod tempor │
│ <q>incididunt ut labore et dolore magna aliqua.</q> │
│ </p> │
│ <p> │
│ Sit amet consectetur <b>adipiscing</b> elit pellentesque habitan… │
│ </p> │
╰───────────────────────────────────────────────────────────────────────╯
🌐 Click to view HTML
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor "incididunt ut labore et dolore magna aliqua."
Sit amet consectetur adipiscing elit pellentesque habitant.
Hyperlinks#
With certain complex content—such as images and HTML—nbpreview will display hyperlinks to them in the render.
% nbpreview --theme material --image-drawing block notebook.ipynb
╭───────────────────────────────────────────────────────────────────────╮
[20]: │ df.head() │
╰───────────────────────────────────────────────────────────────────────╯
[20]: 🌐 Click to view HTML
[20]: sepalLength sepalWidth petalLength petalWidth species
───────────────────────────────────────────────────────────────────
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
╭───────────────────────────────────────────────────────────────────────╮
[21]: │ df.pipe( │
│ (sns.kdeplot, "data"), │
│ x="petalLength", │
│ hue="species", │
│ fill=True, │
│ alpha=1, │
│ ) │
╰───────────────────────────────────────────────────────────────────────╯
[21]: <AxesSubplot:xlabel='petalLength', ylabel='Density'>
🖼 Click to view Image
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀
▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀
▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▄▄▄ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▄ ▄ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▄ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀ ▀▀▀▀
▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀ ▀▀ ▀▀
▀▄▀ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀ ▀ ▀▀▀▀▀
▄▄▄ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀ ▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀
▄ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀ ▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▄ ▄ ▄ ▄ ▄ ▄ ▄
▀ ▀ ▀▀ ▀ ▀ ▀
▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀▀▀▀▀▀▀
╭───────────────────────────────────────────────────────────────────────╮
[6]: │ VegaLite( │
│ { │
│ "$schema": "https://vega.github.io/schema/vega-lite/v5.json", │
│ "width": 300, │
│ "height": 200, │
│ "data": { │
│ "url": "https://raw.githubusercontent.com/vega/vega-data… │
│ }, │
│ "mark": "area", │
│ "encoding": { │
│ "x": {"timeUnit": "yearmonth", "field": "date", "axis": … │
│ "y": {"aggregate": "sum", "field": "count"}, │
│ "color": {"field": "series", "scale": {"scheme": "catego… │
│ }, │
│ } │
│ ) │
╰───────────────────────────────────────────────────────────────────────╯
📊 Click to view Vega chart
▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀ ▀ ▀▀▀▀▀▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀
▀▀▀ ▀ ▀▀▀ ▀▀▀ ▀▀ ▀▀ ▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀
▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀ ▀▀▀▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
The hyperlinks will only work if supported by the terminal.
nbpreview attempts to detect this,
but it can be manually controlled
through the --hyperlinks
or --no-hyperlinks
options.
If hyperlinks are not enabled,
the link address will instead be directly printed to the terminal
so that it’s easy to click or copy.
By default,
nbpreview displays a hint message
that prompts the user to click on the link.
These hints may be removed
by using the --hide-hyperlink-hints
(or -y
)
option.
To create previews,
nbpreview will write the content to temporary files
as the notebook is rendered.
To prevent nbpreview from writing files to your machine,
use the --no-files
(or -l
)
option.
Nerd Fonts#
By default,
nbpreview uses emoji to highlight certain content
(like clickable links).
Instead of using emoji,
nbpreview also supports using icons from Nerd Fonts5.
Simply use the --nerd-font
option
to enable them.
Attention
You’ll need to have a Nerd Font installed and applied
to your terminal to view the Nerd Font icons—or
else you’ll get tofu (
) characters where the icons should be.
Stderr#
Similar to Jupyter Notebooks, stderr text is highlighted in a bright red box.
% nbpreview --theme material notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[5]: │ with pm.Model() as model: │
│ pm.Normal("normal", mu=0, sd=1) │
│ trace = pm.sample(return_inferencedata=True) │
╰────────────────────────────────────────────────────────────────────────╯
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [normal]
🌐 Click to view HTML
100.00% [8000/8000 00:01<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 1_000 tune and 1_000 draw iterations (4_000 +
4_000 draws total) took 12 seconds.
Tracebacks#
Tracebacks are rendered with syntax highlighting.
% nbpreview --theme material notebook.ipynb
╭────────────────────────────────────────────────────────────────────────╮
[1]: │ 1 / 0 │
╰────────────────────────────────────────────────────────────────────────╯
------------------------------------------------------------------------…
ZeroDivisionError Traceback (most recent call
last)
<ipython-input-1-bc757c3fda29> in <module>
----> 1 1 / 0
ZeroDivisionError: division by zero
- 1
Like always, do not view notebooks from untrusted sources.
- 2
curl is a command-line tool to transfer data from servers. In this example it was used to download the file contents from an address.
- 3
jq is a command-line JSON processor. Since Jupyter notebook (
ipynb
) files are in a JSON format, it can be used to filter and transform cells.- 4
fgrep is equivalent to running
grep -F
—which searches an input file for the literal text given.- 5
Nerd Fonts are fonts patched with support for extra icons.