import plotly.plotly as py
import numpy as np
def get_random_data(N):
return np.random.random(N), np.random.random(N), np.random.random(N)
def make_fig(camera, name, N=40):
x1, y1, z1 = get_random_data(N)
trace1 = dict(
type= 'scatter3d',
x=x1,
y=y1,
z=z1,
mode='markers'
)
layout = dict(
title='camera controls - {}'.format(name),
scene=dict(
camera=camera
)
)
fig = dict(data=[trace1], layout=layout)
return fig
The camera position is determined by three vectors: up, center, eye.
The up vector determines the up direction on the page. The default is $(x=0, y=0, z=1)$, that is, the z-axis points up.
The center vector determines the translation about the center of the scene. By default, there is no translation: the center vector is $(x=0, y=0, z=0)$.
The eye vector determines the camera view point about the origin. The default is $(x=1.25, y=1.25, z=1.25)$.
name = 'default'
camera = dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=1.25, y=1.25, z=1.25)
)
fig = make_fig(camera, name)
py.iplot(fig, validate=False, filename=name)
name = 'eye = (x:2, y:2, z:0.1)'
camera = dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=2, y=2, z=0.1)
)
fig = make_fig(camera, name)
py.iplot(fig, validate=False, filename=name)
name = 'eye = (x:0.1, y:2.5, z:0.1)'
camera = dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=0.1, y=2.5, z=0.1)
)
fig = make_fig(camera, name)
py.iplot(fig, validate=False, filename=name)
name = 'eye = (x:2.5, y:0.1, z:0.1)'
camera = dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=2.5, y=0.1, z=0.1)
)
fig = make_fig(camera, name)
py.iplot(fig, validate=False, filename=name)
name = 'eye = (x:0.1, y:0.1, z:2.5)'
camera = dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=0.1, y=0.1, z=2.5)
)
fig = make_fig(camera, name)
py.iplot(fig, validate=False, filename=name)
... by reducing the norm the eye vector.
name = 'eye = (x:0.1, y:0.1, z:1)'
camera = dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=0.1, y=0.1, z=1)
)
fig = make_fig(camera, name)
py.iplot(fig, validate=False, filename=name)
About Plotly
Big thanks to
from IPython.display import display, HTML
import urllib2
url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css'
display(HTML(urllib2.urlopen(url).read()))