Skip to main content

Making before/after image sliders in JupyterLab

Project description

Jupyter Splitview

Binder JupyterLight
A cell magic that displays images in splitview using https://github.com/NUKnightLab/juxtapose.
Note : Still work in progress, there will be breaking changes.
Note 2: JupyterLite Demo by pressing JupyterLight will come soon.

Installation

pip install jupyter-splitview

Example

import jupyter_splitview
%%splity

from skimage import data
from skimage.util import random_noise
import matplotlib.pyplot as plt

img = data.chelsea()
noisy_img = random_noise(img, var=0.02)

fig, ax1 = plt.subplots()
ax1.axis("off")
ax1.imshow(img)

fig, ax2 = plt.subplots()
ax2.axis("off")
ax2.imshow(noisy_img)

Note: The split view widget is still responsive after closing and reopening the notebook without running the cell again.

Another example:

%%splity --position 73% --height auto

import matplotlib.pyplot as plt
import numpy as np

array1 = np.full((15, 30), 10)
array2 = np.random.randint(0, 10, size=(15, 30))
fig, ax1 = plt.subplots(figsize=(5, 10))
ax1.imshow(array1)
fig, ax2 = plt.subplots(figsize=(5, 10))
ax2.imshow(array2)

Notebook arguments

  • --position 73% will set the slider start position to 73%.
  • The height of the widget.
  • --height 220 will set the height to 220 pixel.
  • When --heightis not provided, the default height of the widget is 300 pixel.
  • --height auto will set the height by the value of the first image's resolution in vertical direction.
  • The widget's width will always be adjusted automatically.

Notebook formatting

Formatting with black can be done this way:

  1. pip install 'black[jupyter]'
  2. black --python-cell-magics splity splitview_magic.ipynb

Developer Installation

  1. git clone --recurse https://github.com/kolibril13/jupyter-splitview (Note: In case that the repo was already cloned e.g. with the GitHub Desktop client, the GitHub submodule has to be loaded via git submodule update --init --recursive)
  2. poetry install

Changelog

Milestones

  • Handle cases where n ≠ 2 images. Currently: All further img are ignored.

  • implement tests, find out how to test a magic class

  • Idea: Second option without using cell magic:

from splitview import Splity # (does not yet exist)
my_splity = Splity(left_layer=img1, right_layer=img2)
display(my_splity)

* Make this work also in VSCode notebooks, [see this issue](https://github.com/NUKnightLab/juxtapose/issues/178).

0.0.8

  • Fixing problem with cell id and notebook reloading
  • Experimentally lowering the dependencies to ipython = ">=6.0.0" and ipykernel = ">=5.0.0" so that jupyterlite will work hopefully.

0.0.7

  • Rewrite of the import of JavaScript and CSS to make it more robust when closing and opening the notebook
  • First attempt to add a JupyterLite example.

0.0.6

Fix poetry workflow

0.0.5

  • Ship the javascript directly with the package, so no internet connection is required
  • use jinja2 to save HTML in separate file
  • load stylesheet and javascript only once in the beginning, and not in every cell that contains the splitview widget.

0.0.4

  • New --height parameter

0.0.3

  • default slider position
  • updated minimal example
  • internal code restructuring and formatting
  • Handle import in non jupyter context

0.0.2

  • save images in base64 strings and don't load images to disk (increases package security).

0.0.1

  • First 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

jupyter-splitview-0.0.8.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

jupyter_splitview-0.0.8-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file jupyter-splitview-0.0.8.tar.gz.

File metadata

  • Download URL: jupyter-splitview-0.0.8.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.13 Linux/5.13.0-1029-azure

File hashes

Hashes for jupyter-splitview-0.0.8.tar.gz
Algorithm Hash digest
SHA256 1e706734805d1dca94bb5cc670275105f28dc9a152715d3467afe47788fff3fb
MD5 a91a488a95d151d1d5a6c4e03149c29d
BLAKE2b-256 90e5dba82b30234c3f552d217ecb82c4fb66a55f97fc250a6ba4393cf743c5d4

See more details on using hashes here.

File details

Details for the file jupyter_splitview-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: jupyter_splitview-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.13 Linux/5.13.0-1029-azure

File hashes

Hashes for jupyter_splitview-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 af39c8920cedffe20aac97bf035e6caf9bdd1d960e70aa9376cc98acb6de8e48
MD5 58f485ad2132299476e5ce3ebade3784
BLAKE2b-256 6526898ea162a84b6ce45fc624e1a10e2b42ca839a06a8ee2cdbc791435f8004

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page