Skip to content

Latest commit

 

History

History
148 lines (103 loc) · 4.14 KB

index.rst

File metadata and controls

148 lines (103 loc) · 4.14 KB

Ipyvolume

IPyvolume is a Python library to visualize 3d volumes and glyphs (e.g. 3d scatter plots), in the Jupyter notebook, with minimal configuration and effort. It is currently pre-1.0, so use at own risk. IPyvolume's volshow is to 3d arrays what matplotlib's imshow is to 2d arrays.

Other (more mature but possibly more difficult to use) related packages are yt, VTK and/or Mayavi.

Feedback and contributions are welcome: Github, Email or Twitter.

Quick intro

Volume

For quick resuls, use ipyvolume.volume.quickvolshow. From a numpy array, we create two boxes, using slicing, and visualize it.

import numpy as np import ipyvolume V = np.zeros((128,128,128)) # our 3d array # outer box V[30:-30,30:-30,30:-30] = 0.75 V[35:-35,35:-35,35:-35] = 0.0 # inner box V[50:-50,50:-50,50:-50] = 0.25 V[55:-55,55:-55,55:-55] = 0.0 ipyvolume.quickvolshow(V, level=[0.25, 0.75], opacity=0.03, level_width=0.1, data_min=0, data_max=1)

Scatter plot

Simple scatter plots are also supported.

import ipyvolume import numpy as np x, y, z = np.random.random((3, 10000)) ipyvolume.quickscatter(x, y, z, size=1, marker="sphere")

Quiver plot

Quiver plots are also supported, showing a vector at each point.

import ipyvolume import numpy as np x, y, z, u, v, w = np.random.random((6, 1000))*2-1 quiver = ipyvolume.quickquiver(x, y, z, u, v, w, size=5)

Built on Ipywidgets

For anything more sophisticed, use ipyvolume.pylab, ipyvolume's copy of matplotlib's 3d plotting (+ volume rendering).

Since ipyvolume is built on ipywidgets, we can link widget's properties.

import ipyvolume.pylab as p3 import numpy as np x, y, z, u, v, w = np.random.random((6, 1000))*2-1 selected = np.random.randint(0, 1000, 100) p3.figure() quiver = p3.quiver(x, y, z, u, v, w, size=5, size_selected=8, selected=selected)

from ipywidgets import FloatSlider, ColorPicker, VBox, jslink size = FloatSlider(min=0, max=30, step=0.1) size_selected = FloatSlider(min=0, max=30, step=0.1) color = ColorPicker() color_selected = ColorPicker() jslink((quiver, 'size'), (size, 'value')) jslink((quiver, 'size_selected'), (size_selected, 'value')) jslink((quiver, 'color'), (color, 'value')) jslink((quiver, 'color_selected'), (color_selected, 'value')) VBox([p3.gcc(), size, size_selected, color, color_selected])

Try changing the slider to the change the size of the vectors, or the colors.

Quick installation

This will most likely work, otherwise read install

pip install ipyvolume
jupyter nbextension enable --py --sys-prefix ipyvolume
jupyter nbextension enable --py --sys-prefix widgetsnbextension

For conda/anaconda, use:

conda install -c conda-forge ipyvolume
pip install ipywidgets~=6.0.0b5 --user

About

Ipyvolume is an offspring project from vaex. Ipyvolume makes use of threejs, and excellent Javascript library for OpenGL/WebGL rendering.

Contents

install examples animation api vr

Changelog

* 0.3
* new
  • axis with labels and ticklabels
  • styling
  • animation (credits also to https://github.com/jeammimi)
  • binary transfers
  • default camera control is trackball
* changed
  • s and ss are now spelled out, size and size_selected

Indices and tables

  • genindex
  • modindex
  • search