Parkinson’s disease in the spinal cord: an exploratory study to establish T2*w, MTR and diffusion-weighted imaging metric values
import plotly.express as px
from plotly.offline import plot
from IPython.core.display import HTML
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
import base64
import plotly.io as pio
pio.renderers.default = "plotly_mimetype"
# Load the data
df = pd.read_csv('../../data/parkinsons-spinalcord-mri-metrics/data/participants.csv')
# Add a column for age groups (35-39, 40-44, etc.)
age_group_labels_list = ['35-39', '40-44', '45-49', '50-54', '55-59', '60-64', '65-69', '70-74', '75-79', '80-84']
df['age_groups'] = pd.cut(df['age'], bins=[35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85], labels=age_group_labels_list)
# Create a list to specify the order of the UPDRSIII groups
UPDRS_group_labels_list = ['CTRL', 'early', 'mid', 'adv']
UPDRS_group_labels_ticks = ['HC', 'Early PD', 'Mid PD', 'Adv PD'] # Add custom text for plotting
# Divide the data based on if the modality was used for each subject ('Y' = yes, 'N' = no)
df_DWI = df[df['DWI'] == 'Y']
df_MTR = df[df['MTR'] == 'Y']
df_T2star = df[df['T2star'] == 'Y']
# Create subplots: 1 row, 2 columns
fig = make_subplots(rows=2, cols=2, row_heights=[0.75, 0.25], column_widths=[0.5, 0.5],)
# Figure dimensions
fig.update_layout(width=760, height=798)
# Load static background image (in the "templates_for_figures" folder) and encode as base64
with open("../templates_for_figures/figure1_template.png", "rb") as image_file:
encoded_image = base64.b64encode(image_file.read()).decode()
### ADD STATIC BACKGROUND IMAGE ###
fig.update_layout(
images=[dict(
source="data:image/png;base64," + encoded_image,
x=-0.155,
y=1.11,
xanchor="left",
yanchor="top",
sizex=1.23,
sizey=4.5,
layer="below",
)],
)
### SUBPLOT 1 ###
# Add histogram for DWI
fig.add_trace(go.Histogram(
x=df_DWI['age_groups'],
name='DWI',
marker=dict(color='#1C5F82'),
showlegend=True,
legendgroup='DWI',
),
row=2, col=1
)
# Add histogram for MTR
fig.add_trace(go.Histogram(
x=df_MTR['age_groups'],
name='MTR',
marker=dict(color='black'),
showlegend=True,
legendgroup='MTR',
),
row=2, col=1
)
# Add histogram for T2star
fig.add_trace(go.Histogram(
x=df_T2star['age_groups'],
name='T2*w',
marker=dict(color='#D1D1D1'),
showlegend=True,
legendgroup='T2*w',
),
row=2, col=1
)
### SUBPLOT 2 ###
# Add histogram for DWI
fig.add_trace(go.Histogram(
x=df_DWI['UPDRSIII_group'],
name='DWI',
marker=dict(color='#1C5F82'),
showlegend=False,
legendgroup='DWI',
),
row=2, col=2
)
# Add histogram for MTR
fig.add_trace(go.Histogram(
x=df_MTR['UPDRSIII_group'],
name='MTR',
marker=dict(color='black'),
showlegend=False,
legendgroup='MTR',
),
row=2, col=2
)
# Add histogram for T2star
fig.add_trace(go.Histogram(
x=df_T2star['UPDRSIII_group'],
name='T2*w',
marker=dict(color='#D1D1D1'),
showlegend=False,
legendgroup='T2*w',
),
row=2, col=2
)
fig.update_layout(
font=dict(family='Arial', size=12, color='black'),
legend=dict(
orientation="h",
yanchor="bottom",
y=0.25,
xanchor="center",
x=0.5
),
plot_bgcolor='white',
)
# Update axis properties for each subplot
fig.update_xaxes(
title="Age",
categoryorder="array",
categoryarray=age_group_labels_list,
tickangle=-45,
gridwidth=0.5,
row=2, col=1
)
fig.update_xaxes(
title="Subject Categories",
categoryorder="array",
categoryarray=UPDRS_group_labels_list,
tickvals=list(range(len(UPDRS_group_labels_list))), # Specify tick positions
ticktext=list(UPDRS_group_labels_ticks), # Provide custom text for each tick
tickangle=0,
gridwidth=0.5,
row=2, col=2
)
fig.update_yaxes(
title="Number of subjects",
showgrid=True,
gridcolor='lightgray',
gridwidth=0.5,
row=2, col=1
)
fig.update_yaxes(
title="Number of subjects",
showgrid=True,
gridcolor='lightgray',
gridwidth=0.5,
row=2, col=2
)
fig.show()
Loading...
Parkinson’s disease in the spinal cord: an exploratory study to establish T2*w, MTR and diffusion-weighted imaging metric values
Parkinson’s disease in the spinal cord: an exploratory study to establish T2*w, MTR and diffusion-weighted imaging metric valuesParkinson’s disease in the spinal cord: an exploratory study to establish T2*w, MTR and diffusion-weighted imaging metric values
Figure 2