first commit
This commit is contained in:
parent
abc6526143
commit
26631f9b48
24 changed files with 1089 additions and 1 deletions
68
Code/6-cbf-graph.py
Normal file
68
Code/6-cbf-graph.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import numpy as np
|
||||
import openpyxl
|
||||
import os.path
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def draw_cbf_graph(region, data, save_path):
|
||||
bar_x = np.array(['0.5', '1', '1.5', '2', '2.5', 'cCBF'])
|
||||
bar_y = np.array(data)
|
||||
color = ['#4CAF50', '#4CAF50', '#4CAF50', '#4CAF50', '#4CAF50', '#478FC1']
|
||||
|
||||
# Plotting the Graph
|
||||
font_color = '#FFFFFF'
|
||||
plt.rcParams['text.color'] = font_color
|
||||
plt.rcParams['axes.labelcolor'] = font_color
|
||||
plt.rcParams['xtick.color'] = font_color
|
||||
plt.rcParams['ytick.color'] = font_color
|
||||
|
||||
plt.figure(facecolor='#000000')
|
||||
ax = plt.axes()
|
||||
ax.set_facecolor('#000000')
|
||||
ax.spines['left'].set_color(font_color)
|
||||
ax.spines['right'].set_color(font_color)
|
||||
ax.spines['bottom'].set_color(font_color)
|
||||
ax.spines['top'].set_color(font_color)
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimHei"] # 设置字体
|
||||
plt.bar(bar_x, bar_y, width=0.5, color=color)
|
||||
|
||||
for i in range(len(bar_x)):
|
||||
plt.text(i - 0.2, bar_y[i] - 2, f"{bar_y[i]:.2f}")
|
||||
|
||||
plt.title(f"221例健康人西门子5延迟数据矫正前后{region}CBF对比")
|
||||
plt.xlabel("PLD")
|
||||
plt.ylabel("CBF")
|
||||
plt.savefig(save_path, dpi=200)
|
||||
plt.cla()
|
||||
plt.close('all')
|
||||
|
||||
|
||||
def main():
|
||||
data_types = ['CBF1', 'CBF2', 'CBF3', 'CBF4', 'CBF5', 'corr-CBF']
|
||||
# 请尝试添加'AnImage_AAL3'图谱,并修复错误
|
||||
atlas_list = ['AnImage_WholeBrain', 'AnImage_BrainLobes']
|
||||
output_dir = r'..\Data\cbf-graph'
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
input_file = r'..\Data\csv-simple-stat.xlsx'
|
||||
workbook = openpyxl.load_workbook(input_file, data_only=True)
|
||||
|
||||
for atlas in atlas_list:
|
||||
cbf_mean_dict = {}
|
||||
for data_type in data_types:
|
||||
worksheet = workbook[f'{atlas}_{data_type}']
|
||||
for column_num in range(2, worksheet.max_column + 1):
|
||||
name = worksheet.cell(row=1, column=column_num).value
|
||||
mean = worksheet.cell(row=worksheet.max_row - 8, column=column_num).value
|
||||
print(atlas, data_type, name, mean)
|
||||
|
||||
if name not in cbf_mean_dict:
|
||||
cbf_mean_dict[name] = []
|
||||
cbf_mean_dict[name].append(mean)
|
||||
|
||||
for region, data in cbf_mean_dict.items():
|
||||
draw_cbf_graph(region, data, os.path.join(output_dir, f'{region}.png'))
|
||||
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue