Visualizing Cerebellum as a Plotly Mesh3d


In [1]:
import plotly
print(plotly.__version__)


2.7.0

In [2]:
import numpy as np

Read data for Cerebellum, defined as a triangulated surface:


In [3]:
vertices=np.loadtxt('cerebellum-v.txt', dtype=np.float32)
faces=np.loadtxt('cerebellum-f.txt', dtype=np.int32)

print (vertices.shape, faces.shape, faces[0,:])


(45406, 3) (90788, 3) [0 1 2]

In [4]:
x,y,z=vertices.T
I, J, K=faces.T

In [5]:
colorscale=[[0.0, 'rgb(253, 225, 197)'],
            [0.1, 'rgb(253, 216, 179)'],
            [0.2, 'rgb(253, 207, 161)'],
            [0.3, 'rgb(253, 194, 140)'],
            [0.4, 'rgb(253, 181, 118)'],
            [0.5, 'rgb(253, 167, 97)'],
            [0.6, 'rgb(253, 153, 78)'],
            [0.7, 'rgb(252, 140, 59)'],
            [0.8, 'rgb(248, 126, 43)'],
            [0.9, 'rgb(243, 112, 27)'],
            [1.0, 'rgb(236, 98, 15)']]

In [6]:
mesh=dict(type='mesh3d',
          x=x,
          y=y,
          z=z,
          colorscale=colorscale, 
          intensity= z,
          i=I,
          j=J,
          k=K,
          name='',
          showscale=False,
          lighting=dict(ambient=0.18,
                        diffuse=1,
                        fresnel=0.1,
                        specular=1,
                        roughness=0.05,
                        facenormalsepsilon=1e-8,
                        vertexnormalsepsilon=1e-15),
          lightposition=dict(x=100,
                             y=200,
                             z=0)
        )

In [7]:
axis_style = dict(showbackground=True, 
                  backgroundcolor="rgb(230, 230,230)",
                  gridcolor="rgb(255, 255, 255)",      
                  zerolinecolor="rgb(255, 255, 255)")
layout=dict(title='Cerebellum',
            width=700, 
            height=700, 
            font=dict(family='Balto'),
            scene=dict(camera=dict(eye=dict( x= 1.15, y=-1.15, z=0.9)),
                       aspectratio=dict(x=0.85, y=1., z=0.8),
                       xaxis=dict(axis_style),
                       yaxis=dict(axis_style),
                       zaxis=dict(axis_style)
                      )
           )

In [8]:
fig=dict(data=[mesh], layout=layout)

In [ ]:
import plotly.plotly as py
py.sign_in('empet', 'api_key')
py.plot(fig, filename='Cerebellum')

'https://plot.ly/~empet/14286'


In [10]:
from IPython.display import HTML
HTML('<iframe src=https://plot.ly/~empet/14286 width=800 height=800></iframe>')


Out[10]:

In [9]:
from IPython.core.display import HTML
def  css_styling():
    styles = open("./custom.css", "r").read()
    return HTML(styles)
css_styling()


Out[9]: