In [1]:
from __future__ import division

import os, sys
import numpy as np
import pandas as pd
import datetime as dt
import random as rd

from IPython.display import display
from math import sin, cos, pi, sqrt

import ezvis3d as v3d


Examples

  • reproduced from http://visjs.org/graph3d_examples.html
  • plot() has the following arguments:
    • save=True and optionally save_name and optionally save_path (default='saved') will save the graph as a stand alone HTML doc under save_path after creating it if necessary
    • notebook (default=True) will not inject require and jquery libs as they are already available in the classical notebook. Set to False to inject them.
    • center (default=True) to center the plot in the output cell area

In [2]:
def z(x, y):
    return 50+ sin(x/50) * cos(y/50) * 50

x_min = 0
x_max = 314
x_num = 50

x_rng = np.linspace(x_min, x_max, x_num)
y_rng = x_rng
li_data = [{'x': x, 'y': y, 'z': z(x, y)}
            for y in y_rng
            for x in x_rng]
df_data = pd.DataFrame(li_data)

g = v3d.Vis3d()
g.width = '600px'
g.height = '600px'
g.style = 'surface'
g.showPerspective = True
g.showGrid = True
g.showShadow = False
g.keepAspectRatio = True
g.verticalRatio = 0.7
g.cameraPosition = {'horizontal' : 0.9,
                    'vertical': 0.4,
                    'distance': 1.5
                   }

g.plot(df_data, save=True, save_path='myfolder', save_name='myplot', dated=True)


Out[2]:

In [3]:
def z(x, y):
    return 50+ sin(x/50) * cos(y/50) * 50

def f(x, y):
    v = z(x, y)
    return '67-100' if v>66 else ('0-33' if v<34 else '34-66')

x_min = 0
x_max = 314
x_num = 50

x_rng = np.linspace(x_min, x_max, x_num)
y_rng = x_rng
li_data = [{'x': x, 'y': y, 'z': z(x, y), 'filter': f(x, y)}
            for y in y_rng
            for x in x_rng]
df_data = pd.DataFrame(li_data)

g = v3d.Vis3d()
g.width = '600px'
g.height = '600px'
g.style = 'surface'
g.showPerspective = False
g.showGrid = True
g.showShadow = False
g.keepAspectRatio = True
g.verticalRatio = 0.7
g.filterLabel = 'values'
g.cameraPosition = {'horizontal' : 0.9,
                    'vertical': 0.4,
                    'distance': 1.5
                   }
g.animationInterval = 1500
g.animationPreload = True
g.animationAutoStart = True

g.plot(df_data)


Out[3]:

In [4]:
def z(x, y, t):
    return 50+ sin(x/50 + t/10) * cos(y/50 + t/10) * 50

x_min = 0
x_max = 314
x_num = 25
t_max = 31
x_rng = np.linspace(x_min, x_max, x_num)
y_rng = x_rng
t_rng = range(t_max)
li_data = [{'x': x, 'y': y, 'z': z(x, y, t), 'filter': t}
            for y in y_rng
            for x in x_rng
            for t in t_rng]
df_data = pd.DataFrame(li_data)

g = v3d.Vis3d()
g.width = '600px'
g.height = '600px'
g.style = 'surface'
g.showPerspective = True
g.showGrid = True
g.showShadow = False
g.keepAspectRatio = True
g.verticalRatio = 0.7
g.filterLabel = 'time'
g.cameraPosition = {'horizontal' : 0.9,
                    'vertical': 0.4,
                    'distance': 1.7
                   }
g.showAnimationControls = True
g.animationInterval = 100
g.animationPreload = True
g.animationAutoStart = True

g.plot(df_data)


Out[4]: