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/04-B1-02-AFI")
data_file = "fig7.mat"

#Load either archived or generated plot variables
mat_contents = sio.loadmat(data_dir / data_file)

B1map_raw = mat_contents["B1map_raw"]
AFIData1 = mat_contents["AFIData1"]
AFIData2 = mat_contents["AFIData2"]
mask = mat_contents["mask"]
xAxis = mat_contents["xAxis"][0]
yAxis = mat_contents["yAxis"][0]

# Masking B1 map
B1map_raw = np.asarray(B1map_raw)
mask = np.asarray(mask)
B1map_raw_masked = B1map_raw*mask
B1map_raw_masked[np.isnan(B1map_raw_masked)] = 0

data_dir = Path("../../../data/04-B1-02-AFI")
data_file = "fig8.mat"


#Load either archived or generated plot variables
mat_contents = sio.loadmat(data_dir / data_file)

B1map_filtered = mat_contents["B1map_filtered"]

## Plot
# PYTHON CODE
# Module imports

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
config={'showLink': False, 'displayModeBar': False}
# PYTHON CODE
from plotly import tools

# Masking B1 map
B1map_filtered = np.asarray(B1map_filtered)
mask = np.asarray(mask)
B1map_filtered_masked = B1map_filtered*mask
B1map_filtered_masked[np.isnan(B1map_filtered_masked)] = 0

trace1 = go.Heatmap(x = xAxis,
                   y = yAxis,
                   z=B1map_raw_masked,
                   zmin=0.7,
                   zmax=1.3,
                   colorscale='RdBu',
                   showscale = False,
                   visible=True,
                   name = 'B1 values')
trace2 = go.Heatmap(x = xAxis,
                   y = yAxis,
                   z=B1map_filtered_masked,
                   zmin=0.7,
                   zmax=1.3,
                   colorscale='RdBu',
                   xaxis='x2',
                   yaxis='y2',
                   visible=True,
                   name = 'B1 values')

data=[trace1, trace2]

layout = dict(
    width=560,
    height=310,
    margin = dict(
                t=40,
                r=50,
                b=10,
                l=50),
    annotations=[
        dict(
            x=0.04,
            y=1.15,
            showarrow=False,
            text='Raw B<sub>1</sub> map',
            font=dict(
                family='Times New Roman',
                size=26
            ),
            xref='paper',
            yref='paper'
        ),
        dict(
            x=0.60,
            y=1.15,
            showarrow=False,
            text='Filtered B<sub>1</sub> map',
            font=dict(
                family='Times New Roman',
                size=26
            ),
            xref='paper',
            yref='paper'
        ),
        dict(
            x=1.12,
            y=1.15,
            showarrow=False,
            text='B<sub>1</sub>',
            font=dict(
                family='Times New Roman',
                size=26
            ),
            xref='paper',
            yref='paper'
        ),
    ],
    xaxis = dict(range = [0,127], autorange = False,
             showgrid = False, zeroline = False, showticklabels = False,
             ticks = '', domain=[0, 0.58]),
    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.40, 0.98]),
    yaxis2 = dict(range = [0,127], autorange = False,
             showgrid = False, zeroline = False, showticklabels = False,
             ticks = '', domain=[0, 1], anchor='x2'),
    showlegend = False,
    autosize = False,
)


fig = dict(data=data, layout=layout)

iplot(fig, filename = 'basic-heatmap', config = config)
Loading...