50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import openpyxl
|
|
import os.path
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
def draw_box_graph(region, data, groups, data_type, save_path):
|
|
plt.rcParams["font.sans-serif"] = ["SimHei"] # 设置字体
|
|
plt.boxplot(data,
|
|
patch_artist=True, # 是否填色
|
|
labels=groups)
|
|
|
|
plt.title(f"各个分组{region}{data_type}对比")
|
|
plt.xlabel("分组")
|
|
plt.ylabel(data_type)
|
|
plt.savefig(save_path, dpi=200)
|
|
plt.cla()
|
|
plt.close('all')
|
|
|
|
|
|
def main():
|
|
data_types = ['corr-CBF', "ATT"]
|
|
# 请尝试添加'AnImage_AAL3'图谱,并修复错误
|
|
atlas_list = ['AnImage_WholeBrain', 'AnImage_BrainLobes']
|
|
output_dir = r'..\Data\box-graph'
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
input_file = r'..\Data\csv-group.xlsx'
|
|
workbook = openpyxl.load_workbook(input_file, data_only=True)
|
|
groups = ['A', 'B', 'C']
|
|
|
|
for data_type in data_types:
|
|
for atlas in atlas_list:
|
|
value_dict = {}
|
|
for group in groups:
|
|
worksheet = workbook[f'{group}_{atlas}_{data_type}']
|
|
for column_num in range(2, worksheet.max_column + 1):
|
|
data = []
|
|
name = worksheet.cell(row=1, column=column_num).value
|
|
for row in range(2, worksheet.max_row - 10):
|
|
data.append(worksheet.cell(row=row, column=column_num).value)
|
|
|
|
if name not in value_dict:
|
|
value_dict[name] = []
|
|
value_dict[name].append(data)
|
|
|
|
for region, data in value_dict.items():
|
|
draw_box_graph(region, data, groups, data_type, os.path.join(output_dir, f'{region}{data_type}.png'))
|
|
|
|
|
|
main()
|