55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
import openpyxl
|
|
import os.path
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
def draw_box_graph(data_dict, groups, data_type, save_path):
|
|
plt.rcParams["font.sans-serif"] = ["SimHei"] # 设置字体
|
|
|
|
grid_height = 2
|
|
grid_width = 4
|
|
|
|
_, ax = plt.subplots(grid_height, grid_width, figsize=(20, 15), sharey=True)
|
|
keys = list(data_dict.keys())
|
|
for x in range(grid_width):
|
|
for y in range(grid_height):
|
|
region_name = keys[x + y * grid_width]
|
|
ax[y][x].boxplot(data_dict[region_name], patch_artist=True, labels=groups)
|
|
ax[y][x].set_title(f"{region_name}{data_type}对比")
|
|
ax[y][x].set_ylabel(data_type)
|
|
|
|
plt.tight_layout()
|
|
plt.savefig(save_path, dpi=200)
|
|
plt.cla()
|
|
plt.close('all')
|
|
|
|
|
|
def main():
|
|
data_types = ['corr-CBF', "ATT"]
|
|
atlas_list = ['AnImage_BrainLobes']
|
|
output_dir = r'..\Data\subplot'
|
|
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)
|
|
|
|
draw_box_graph(value_dict, groups, data_type, os.path.join(output_dir, f'{atlas}_{data_type}.png'))
|
|
|
|
|
|
main()
|