from repo2data.repo2data import Repo2Data
import os
import pickle
import matplotlib.pyplot as plt
import chart_studio.plotly as py
import plotly.graph_objs as go
import numpy as np
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
from IPython.display import display, HTML
from plotly import tools
from contextlib import contextmanager
import sys, os
@contextmanager
def suppress_stdout():
with open(os.devnull, "w") as devnull:
old_stdout = sys.stdout
sys.stdout = devnull
try:
yield
finally:
sys.stdout = old_stdout
with suppress_stdout():
data_req_path = os.path.join("..","..","..", "binder", "data_requirement.json")
repo2data = Repo2Data(data_req_path)
DATA_ROOT = os.path.join(repo2data.install()[0],"t1-book-neurolibre")
filename = os.path.join(DATA_ROOT,"01",'figure_5.pkl')
with open(filename, 'rb') as f:
T1_map, TI_0030, TI_0530, TI_1030, TI_1530, xAxis, yAxis = pickle.load(f)
config={'showLink': False, 'displayModeBar': False}
init_notebook_mode(connected=True)
trace1 = go.Heatmap(x = xAxis,
y = yAxis,
z=TI_0030,
colorscale='gray',
showscale = False,
visible=False,
name = 'Signal')
trace2 = go.Heatmap(x = xAxis,
y = yAxis,
z=TI_0530,
colorscale='gray',
showscale = False,
visible=False,
name = 'Signal')
trace3 = go.Heatmap(x = xAxis,
y = yAxis,
z=TI_1030,
colorscale='gray',
showscale = False,
visible=True,
name = 'Signal')
trace4 = go.Heatmap(x = xAxis,
y = yAxis,
z=TI_1530,
colorscale='gray',
visible=False,
showscale = False,
name = 'Signal')
trace5 = go.Heatmap(x = xAxis,
y = yAxis,
z=T1_map,
colorscale='Portland',
xaxis='x2',
yaxis='y2',
visible=True,
name = 'T1 values (ms)')
data=[trace1, trace2, trace3, trace4, trace5]
updatemenus = list([
dict(active=2,
x = 0.12,
xanchor = 'left',
y = -0.15,
yanchor = 'bottom',
direction = 'up',
font=dict(
family='Times New Roman',
size=16
),
buttons=list([
dict(label = '30 ms',
method = 'update',
args = [{'visible': [True, False, False, False, True]},
]),
dict(label = '530 ms',
method = 'update',
args = [{'visible': [False, True, False, False, True]},
]),
dict(label = '1030 ms',
method = 'update',
args = [{'visible': [False, False, True, False, True]},
]),
dict(label = '1530 ms',
method = 'update',
args = [{'visible': [False,False, False, True, True]},
])
]),
)
])
layout = dict(
width=560,
height=345,
margin = dict(
t=40,
r=50,
b=10,
l=50),
annotations=[
dict(
x=0.06,
y=1.15,
showarrow=False,
text='MR Image',
font=dict(
family='Times New Roman',
size=26
),
xref='paper',
yref='paper'
),
dict(
x=0.6,
y=1.15,
showarrow=False,
text='T<sub>1</sub> map',
font=dict(
family='Times New Roman',
size=26
),
xref='paper',
yref='paper'
),
dict(
x=1.22,
y=1.15,
showarrow=False,
text='T<sub>1</sub> (ms)',
font=dict(
family='Times New Roman',
size=26
),
xref='paper',
yref='paper'
),
dict(
x=0.02,
y=-0.15,
showarrow=False,
text='TI:',
font=dict(
family='Times New Roman',
size=22
),
xref='paper',
yref='paper'
),
],
xaxis = dict(range = [0,127], autorange = False,
showgrid = False, zeroline = False, showticklabels = False,
ticks = '', domain=[0, 0.6]),
yaxis = dict(range = [0,127], autorange = False,
showgrid = False, zeroline = False, showticklabels = False,
ticks = '', domain=[0, 1]),
xaxis2 = dict(range = [0,127], autorange = False,
showgrid = False, zeroline = False, showticklabels = False,
ticks = '', domain=[0.4, 1]),
yaxis2 = dict(range = [0,127], autorange = False,
showgrid = False, zeroline = False, showticklabels = False,
ticks = '', domain=[0, 1], anchor='x2'),
showlegend = False,
autosize = False,
updatemenus=updatemenus,
plot_bgcolor='white'
)
fig = dict(data=data, layout=layout)
iplot(fig, filename = 'ir_fig_5.html', config = config)
Loading...