ipypublish.scripts.nb_setup module

Some useful functions for creating publishable jupyter notebooks

usage:

from ipypublish import nb_setup
plt = nb_setup.setup_matplotlib(
    print_errors=True,
    output=('pdf',))
pd = nb_setup.setup_pandas(escape_latex=True)
sym = nb_setup.setup_sympy()
import numpy as np
from IPython.display import Image, Latex
ipypublish.scripts.nb_setup.create_test_image(size=50, 50)[source]
ipypublish.scripts.nb_setup.get_pimage()[source]
ipypublish.scripts.nb_setup.images_gridconcat(pathslist, width=700, height=700, aspaths=True, hgap=0, vgap=0)[source]

concatenate multiple images in a grid

Parameters
  • pathslist (list[list]) – if aspaths=True, list of path strings, else list of PIL.Image instances each sub list constitutes a row

  • width (int) – maximum width of final image

  • height (int) – maximum height of final image

  • hgap (int) – size of horizontal space between images

  • vgap (int) – size of vertical space between images

Returns

image

Return type

PIL.Image

ipypublish.scripts.nb_setup.images_hconcat(images, width=700, height=700, gap=0, aspaths=True)[source]

concatenate multiple images horizontally

Parameters
  • images (list) – if aspaths=True, list of path strings, else list of PIL.Image instances

  • width (int or list[int]) – maximum width of final image, or of individual images

  • height (int or list[int]) – maximum height of final image, or of individual images

  • gap (int) – size of space between images

Returns

image

Return type

PIL.Image

Examples

>>> img_path = create_test_image(size=(50,50))
>>> img = images_hconcat([img_path,img_path])
>>> img.size
(100, 50)
>>> img_path = create_test_image(size=(50,50))
>>> img = images_hconcat([img_path,img_path],width=40,height=40)
>>> img.size
(40, 20)
>>> img_path = create_test_image(size=(50,50))
>>> img = images_hconcat([img_path,img_path],width=[40,30])
>>> img.size
(70, 40)
>>> img_path = create_test_image(size=(50,50))
>>> img = images_hconcat([img_path,img_path],gap=10)
>>> img.size
(110, 50)
ipypublish.scripts.nb_setup.images_read(paths)[source]

read a list of image paths to a list of PIL.IMAGE instances

ipypublish.scripts.nb_setup.images_vconcat(images, width=700, height=700, gap=0, aspaths=True)[source]

concatenate multiple images vertically

Parameters
  • images (list) – if aspaths=True, list of path strings, else list of PIL.Image instances

  • width (int or list[int]) – maximum width of final image, or of individual images

  • height (int or list[int]) – maximum height of final image, or of individual images

  • gap (int) – size of space between images

Returns

image

Return type

PIL.Image

Examples

>>> img_path = create_test_image(size=(50,50))
>>> img = images_vconcat([img_path,img_path])
>>> img.size
(50, 100)
>>> img_path = create_test_image(size=(50,50))
>>> img = images_vconcat([img_path,img_path],width=40,height=40)
>>> img.size
(20, 40)
>>> img_path = create_test_image(size=(50,50))
>>> img = images_vconcat([img_path,img_path],width=[40,30])
>>> img.size
(40, 70)
>>> img_path = create_test_image(size=(50,50))
>>> img = images_vconcat([img_path,img_path],gap=10)
>>> img.size
(50, 110)
ipypublish.scripts.nb_setup.setup_matplotlib(output='pdf', 'svg', rcparams=None, usetex=True, print_errors=False)[source]

import and setup matplotlib in the jupyter notebook

Parameters
  • output (tuple[str]) – the output formats to save to the notebook

  • rcparams (None or dict) – update default parameters set for matplotlib

  • usetex (bool) – if True, and the ‘latex’ command is available, create figures with LaTeX

  • print_errors (bool) – print errors for unavailable rcparams

ipypublish.scripts.nb_setup.setup_pandas(escape_latex=False, use_longtable=False)[source]

import and setup pandas in the jupyter notebook

Parameters

escape_latex (bool) – whether to escape special latex character, e.g. _ -> _

ipypublish.scripts.nb_setup.setup_sympy()[source]