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
Python 3.7 or higher required.
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.ipynb
with the code to loadmydata.txt
withpandas.read_csv
and 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
numpy
template, usingnumpy.genfromtxt
to 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
imshow
template to generate a notebook that loads and displays the 2 images with matplotlibimshow
andPIL.Image
.
$ nbplot -t imshow paste-image
- Use the special
paste-image
filename 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
daltonize
template 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.
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.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file nbplot-0.2.tar.gz
.
File metadata
- Download URL: nbplot-0.2.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a49be09e2514492334cdd592496601222a4925d5572a7b184ae3f3c0942da5c |
|
MD5 | 8cf605f31d1e776a823684fd5ec5fc20 |
|
BLAKE2b-256 | 44d0e31922d434eb43db100c1e83ac8ca73e69bbc4267deb7d4a91dfed2b9648 |
File details
Details for the file nbplot-0.2-py3-none-any.whl
.
File metadata
- Download URL: nbplot-0.2-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9054a8b2fb9b7bff03707e6f38e61ffb6a5607a0a98a61c60b88d3d20cc4355c |
|
MD5 | c09df58fc154c3e49ac354f3579370ea |
|
BLAKE2b-256 | 8c6cb728cb6e997eb51ba64fd7634478019d035c7a96de0938cee11c6a870d8e |