#!/usr/bin/env python # coding: utf-8 # # Plotly 3D camera controls #
#
# In[1]: import plotly.plotly as py # In[2]: import numpy as np def get_random_data(N): return np.random.random(N), np.random.random(N), np.random.random(N) # In[3]: 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 # ### Default params # # 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)$. # In[4]: 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) # ### Lower the view point # In[5]: 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) # ### x-z plane # In[6]: 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) # ### y-z plane # In[7]: 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) # ### view from above # In[8]: 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) # ### zooming in # # ... by reducing the norm the eye vector. # In[9]: 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) #
# #
# #

Got Questions or Feedback?

# # About Plotly # # * email: feedback@plot.ly # * tweet: # @plotlygraphs # #

Notebook styling ideas

# # Big thanks to # # * Cam Davidson-Pilon # * Lorena A. Barba # #
# In[10]: 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()))