{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ " ## Visualizing Cerebellum as a Plotly Mesh3d ##" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.7.0\n" ] } ], "source": [ "import plotly\n", "print(plotly.__version__)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Read data for Cerebellum, defined as a triangulated surface:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(45406, 3) (90788, 3) [0 1 2]\n" ] } ], "source": [ "vertices=np.loadtxt('cerebellum-v.txt', dtype=np.float32)\n", "faces=np.loadtxt('cerebellum-f.txt', dtype=np.int32)\n", "\n", "print (vertices.shape, faces.shape, faces[0,:])" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "x,y,z=vertices.T\n", "I, J, K=faces.T" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "colorscale=[[0.0, 'rgb(253, 225, 197)'],\n", " [0.1, 'rgb(253, 216, 179)'],\n", " [0.2, 'rgb(253, 207, 161)'],\n", " [0.3, 'rgb(253, 194, 140)'],\n", " [0.4, 'rgb(253, 181, 118)'],\n", " [0.5, 'rgb(253, 167, 97)'],\n", " [0.6, 'rgb(253, 153, 78)'],\n", " [0.7, 'rgb(252, 140, 59)'],\n", " [0.8, 'rgb(248, 126, 43)'],\n", " [0.9, 'rgb(243, 112, 27)'],\n", " [1.0, 'rgb(236, 98, 15)']]" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "mesh=dict(type='mesh3d',\n", " x=x,\n", " y=y,\n", " z=z,\n", " colorscale=colorscale, \n", " intensity= z,\n", " i=I,\n", " j=J,\n", " k=K,\n", " name='',\n", " showscale=False,\n", " lighting=dict(ambient=0.18,\n", " diffuse=1,\n", " fresnel=0.1,\n", " specular=1,\n", " roughness=0.05,\n", " facenormalsepsilon=1e-8,\n", " vertexnormalsepsilon=1e-15),\n", " lightposition=dict(x=100,\n", " y=200,\n", " z=0)\n", " )\n", " " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "axis_style = dict(showbackground=True, \n", " backgroundcolor=\"rgb(230, 230,230)\",\n", " gridcolor=\"rgb(255, 255, 255)\", \n", " zerolinecolor=\"rgb(255, 255, 255)\")\n", "layout=dict(title='Cerebellum',\n", " width=700, \n", " height=700, \n", " font=dict(family='Balto'),\n", " scene=dict(camera=dict(eye=dict( x= 1.15, y=-1.15, z=0.9)),\n", " aspectratio=dict(x=0.85, y=1., z=0.8),\n", " xaxis=dict(axis_style),\n", " yaxis=dict(axis_style),\n", " zaxis=dict(axis_style)\n", " )\n", " )" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "fig=dict(data=[mesh], layout=layout)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import plotly.plotly as py\n", "py.sign_in('empet', 'api_key')\n", "py.plot(fig, filename='Cerebellum')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`'https://plot.ly/~empet/14286'`" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import HTML\n", "HTML('')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.core.display import HTML\n", "def css_styling():\n", " styles = open(\"./custom.css\", \"r\").read()\n", " return HTML(styles)\n", "css_styling()" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:python36]", "language": "python", "name": "conda-env-python36-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 1 }