Command-line utility to quickly plot files in a Jupyter notebook
Project description
nbplot
Command-line utility to quickly plot files in a Jupyter notebook.
Tools like pandas+matplotlib are very powerful, but it takes some time to plot a file from scratch: run a Jupyter notebook instance, create a notebook, import the modules, go grab the path of the file, remember how to call read_csv properly, create the matplotlib figure, etc. The goal of nbplot is to remove that friction and make this as easy as launching a dedicated tool like gnuplot.
Demo
Installation
Tested on Python 3.8 to 3.12, but it likely works on more versions.
pip install nbplot
Features
-
Can be fully configured via templates. A template is just a notebook with some special variables that will get replaced.
-
Ships with a default template for numpy+matplotlib and one for pandas+matplotlib.
-
Can guess the column delimiter of text files.
-
Data can be directly read from stdin, and the string will be embedded in the generated notebook.
-
Will try to reuse an existing instance of notebook server (inspired by nbopen).
Examples
Plots
$ cat mydata.txt
1 1
2 4
3 9
4 16
$ nbplot mydata.txt
-
Generates a notebook
~/nbplot/{{date}}-mydata.ipynbwith the code to loadmydata.txtwithpandas.read_csvand the guessed space delimiter. -
Opens the notebook in the browser, reusing existing instances of Jupyter if possible, starting a new one otherwise.
$ nbplot -t numpy mydata.txt
- Generates the notebook with the
numpytemplate, usingnumpy.genfromtxtto load the file.
$ nbplot mydata1.txt mydata2.txt [...]
- Generates a notebook that loads all the input files in the same plot.
$ for i in `seq -10 10`; do echo $i $((i*i)); done | nbplot -
- Reads the data to plot from stdin and generates a notebook to plot it, with the data embedded as a string.
Images
$ nbplot -t imshow image1.png image2.jpg
- Uses the
imshowtemplate to generate a notebook that loads and displays the 2 images with matplotlibimshowandPIL.Image.
$ nbplot -t imshow paste-image
- Use the special
paste-imagefilename to directly plot an image from the clipboard. It will get embedded into the notebook via a base64 string.
$ nbplot -t daltonize Ishihara_9_from_wikipedia.png
- The
daltonizetemplate generates a notebook with the same image rendered with various color filters that can either help color-blind people to better see the contrasts, or designers to simulate different kinds of color blindness. Powered by the daltonize module.
Empty notebook, no input files
$ nbplot -t empty -o empty.ipynb
- Creates an empty notebook in the current folder with the name
empty.ipynband opens it.
Creating a custom template
Templates are just regular .ipynb notebooks, with special variables like the filenames to plot that will get replaced when generating the output notebook.
The easiest way to create a custom template is to copy and adapt an existing one from the templates/ folder of the repository, and put it in your ~/.nbplot/ folder, next to the configuration file. The name of the template is defined in metadata dictionary defined in the special cell that stars with a # [[nbplot]] template line.
The search for template files is recursive, so it is possible to manage custom templates in e.g. an external repository and git clone it in a subfolder under ~/.nbplot.
Configuring the default behavior
When first launched, nbplot generates a configuration file in ~/.nbplot/config.ipynb. It is also a notebook, and the config dictionary will be read after evaluating the cell. The main options are the default template, the folder from which to start the notebook instance, and the folder where the generated plots will be saved.
ChangeLog
v0.3 (April 6th, 2021)
- Add an empty template and accept to run without input files
- Fix the recursive globbing of user templates to follow symlinks
- Fix the image type conversion in the daltonize template
v0.2 (April 4th, 2021)
New features:
- Add an
imshowtemplate to show images withmatplotlib.imshow. - Add a
daltonizetemplate to show images enhanced for colorblind people. - Glob templates recursively in
~/.nbplot. This makes it possible to manage private templates via a git cloned subfolder. - Add the
paste-imagespecial filename to grab an image from the clipboard and embed its content in the notebook.
Fixes:
- Fix the metadata to automatically load a Python kernel.
- Don't fail when trying to determine the delimiter on binary files.
pandas: handle files with multiple spaces / tabs between columns.
v0.1 (April 1st, 2021)
Initial release.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nbplot-0.4.tar.gz.
File metadata
- Download URL: nbplot-0.4.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1a71b4ad704d7255fbb6bab756123fdf9293d90b30dc3a3389e7de073bbcb5c
|
|
| MD5 |
b5bfc0d9fa14ede6655e361b8842aaea
|
|
| BLAKE2b-256 |
206199b5467ec72646e8f2f271f8fce5ddd916439221b28ee035835049a31e52
|
File details
Details for the file nbplot-0.4-py3-none-any.whl.
File metadata
- Download URL: nbplot-0.4-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09577615d86e79b7d1f2f8c99193952c22843569bdef89d718a90904b7b8eb67
|
|
| MD5 |
7bb6ba568c2e745e563765eb92b8d321
|
|
| BLAKE2b-256 |
f702a99ed89065ddf811f512cc84cc8e48daf79b1a97a1bcc617042fc6f7bec4
|