Skip to article frontmatterSkip to article content
# Prepare Python environment

import scipy.io as sio
import numpy as np
from pathlib import Path

data_dir = Path("../../../data/06-MT-03-MTsat")
data_file_a = "fig2a_mtsat.mat"
data_file_b = "fig2b_mtsat.mat"

#Load either archived or generated plot variables
mat_contents_a = sio.loadmat(data_dir / data_file_a)
mat_contents_b = sio.loadmat(data_dir / data_file_b)

MTsats_uncorr = mat_contents_a["MTsats"][0]
MTRs_uncorr = mat_contents_a["MTRs"][0]
B1s_uncorr = mat_contents_a["B1_range"][0]
T1s_uncorr = mat_contents_a["T1s"][0]

MTsats_corr = mat_contents_b["MTsats"][0]
MTRs_corr = mat_contents_b["MTRs"][0]
B1s_corr = mat_contents_b["B1_range"][0]
T1s_corr = mat_contents_b["T1s"][0]

# Plot Figure 1

# Module imports

import matplotlib.pyplot as plt
import plotly as py
import plotly.graph_objs as go
import numpy as np
from plotly import __version__
from plotly.subplots import make_subplots

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
config={'showLink': False, 'displayModeBar': False}

init_notebook_mode(connected=True)

# PYTHON CODE

init_notebook_mode(connected=True)
# The polling here is to ensure that plotly.js has already been loaded before
# setting display alignment in order to avoid a race condition.

## Setup for plots
fig = make_subplots(rows=1, cols=3, horizontal_spacing = 0.1)


fig.add_trace(
        go.Scatter(
        x=B1s_uncorr,
        y=MTRs_uncorr,
        hoverinfo = 'y',
        showlegend=False,
        visible=True
        ), row= 1, col=1
    )
fig.add_trace(
        go.Scatter(
        x=B1s_uncorr,
        y=T1s_uncorr,
        hoverinfo = 'y',
        showlegend=False,
        visible=True
        ), row= 1, col=2
    )
fig.add_trace(
        go.Scatter(
        x=B1s_uncorr,
        y=MTsats_uncorr,
        hoverinfo = 'y',
        showlegend=False,
        visible=True
        ), row= 1, col=3
    )


fig.add_trace(
        go.Scatter(
        x=B1s_uncorr,
        y=MTRs_corr,
        hoverinfo = 'y',
        showlegend=False,
        visible=False
        ), row= 1, col=1
    )
fig.add_trace(
        go.Scatter(
        x=B1s_uncorr,
        y=T1s_corr,
        hoverinfo = 'y',
        showlegend=False,
        visible=False
        ), row= 1, col=2
    )
fig.add_trace(
        go.Scatter(
        x=B1s_corr,
        y=MTsats_corr,
        hoverinfo = 'y',
        showlegend=False,
        visible=False
        ), row= 1, col=3
    )

layout = go.Layout(
    width=720,
    height=300,
    margin=go.layout.Margin(
        l=60,
        r=30,
        b=60,
        t=60,
    ),
    annotations=[
        dict(
            x=-0.15,
            y=0.50,
            showarrow=False,
            text='MTsat (%)',
            font=dict(
                family='Times New Roman',
                size=22
            ),
            textangle=-90,
            xref='paper',
            yref='paper'
        ),
        dict(
            x=-0.15,
            y=0.50,
            showarrow=False,
            text='MTsat (%)',
            font=dict(
                family='Times New Roman',
                size=22
            ),
            textangle=-90,
            xref='paper',
            yref='paper'
        ),
        dict(
            x=0.51,
            y=-0.3,
            showarrow=False,
            text='B<sub>1</sub>',
            font=dict(
                family='Times New Roman',
                size=22
            ),
            textangle=0,
            xref='paper',
            yref='paper'
        ),
        dict(
            x=0.9,
            y=-0.3,
            showarrow=False,
            text='B<sub>1</sub>',
            font=dict(
                family='Times New Roman',
                size=22
            ),
            textangle=0,
            xref='paper',
            yref='paper'
        ),
        dict(
            x=0.12,
            y=-0.3,
            showarrow=False,
            text='B<sub>1</sub>',
            font=dict(
                family='Times New Roman',
                size=22
            ),
            textangle=0,
            xref='paper',
            yref='paper'
        ),
        dict(
            x=-0.08,
            y=0.5,
            showarrow=False,
            text='MTR',
            font=dict(
                family='Times New Roman',
                size=22
            ),
            textangle=-90,
            xref='paper',
            yref='paper'
        ),
        dict(
            x=0.28,
            y=0.5,
            showarrow=False,
            text='T<sub>1</sub> (s)',
            font=dict(
                family='Times New Roman',
                size=22
            ),
            textangle=-90,
            xref='paper',
            yref='paper'
        ),
        dict(
            x=0.69,
            y=0.5,
            showarrow=False,
            text='MTsat (%)',
            font=dict(
                family='Times New Roman',
                size=22
            ),
            textangle=-90,
            xref='paper',
            yref='paper'
        ),
        dict(
            x=0.22,
            y=-0.55,
            showarrow=False,
            text='B<sub>1</sub> correction?',
            font=dict(
                family='Times New Roman',
                size=22
            ),
            xref='paper',
            yref='paper'
        ),
    ],
    xaxis=dict(
        showgrid=True,
        gridcolor='rgb(169,169,169)',
        linecolor='black',
        linewidth=2
    ),
    yaxis=dict(
        showgrid=True,
        gridcolor='rgb(169,169,169)',
        linecolor='black',
        linewidth=2,
        range=[35,55]
    ),
    xaxis2=dict(
        showgrid=True,
        gridcolor='rgb(169,169,169)',
        linecolor='black',
        linewidth=2,
    ),
    yaxis2=dict(
        showgrid=True,
        gridcolor='rgb(169,169,169)',
        linecolor='black',
        linewidth=2,
        range=[0.3,0.9]
    ),
    xaxis3=dict(
        showgrid=True,
        gridcolor='rgb(169,169,169)',
        linecolor='black',
        linewidth=2
    ),
    yaxis3=dict(
        showgrid=True,
        gridcolor='rgb(169,169,169)',
        linecolor='black',
        linewidth=2,
        range=[4,7]
    ),
)

fig.update_layout(
    updatemenus=[
        dict(
            type="buttons",
            direction="right",
            active=0,
            x=0.57,
            y=-0.3,
            buttons=list([
                dict(label="No",
                     method="update",
                     args=[{"visible": [True, True, True, False, False, False]},
                           ]),
                dict(label="Yes",
                     method="update",
                     args=[{"visible": [False, False, False, True, True, True]},
                           ]),
            ]),
        )
    ])

fig.update_layout(layout)

iplot(fig, filename = 'fig4.html', config = config)
Loading...