Ethscriptions commited on
Commit
cc04e5d
·
verified ·
1 Parent(s): f2ceacd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -77,18 +77,29 @@ def create_print_layout(data, title):
77
  return None
78
 
79
  # 设置 A5 纵向尺寸(单位:英寸)
80
- fig, axes = plt.subplots(figsize=(5.83, 8.27), dpi=300, nrows=len(data), ncols=1)
 
 
 
 
 
 
 
81
 
82
  # 设置字体和样式
83
  plt.rcParams['font.family'] = 'sans-serif'
84
  plt.rcParams['font.sans-serif'] = ['SimHei'] # 中文字体
85
 
86
  # 计算适合的字体大小
87
- base_fontsize = 45 # 增加基础字体大小
88
 
89
  # 填充数据
90
  for idx, (hall, end_time) in enumerate(data.values):
91
- ax = axes[idx]
 
 
 
 
92
 
93
  # 设置更深的边框颜色
94
  for spine in ax.spines.values():
@@ -103,13 +114,14 @@ def create_print_layout(data, title):
103
  ha='center',
104
  va='center')
105
 
 
 
 
 
106
  # 移除坐标轴
107
  ax.set_xticks([])
108
  ax.set_yticks([])
109
 
110
- # 调整图形大小,减少多余边距
111
- fig.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02)
112
-
113
  # 将图表转换为 base64 字符串
114
  buffer = io.BytesIO()
115
  plt.savefig(buffer, format='png', bbox_inches='tight', pad_inches=0.05) # 减小边距
 
77
  return None
78
 
79
  # 设置 A5 纵向尺寸(单位:英寸)
80
+ fig = plt.figure(figsize=(5.83, 8.27), dpi=300)
81
+
82
+ # 减小边距,最大化利用空间
83
+ plt.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02)
84
+
85
+ # 创建网格,减小间距
86
+ rows = (len(data) + 2) // 3 # 向上取整除法
87
+ gs = gridspec.GridSpec(rows, 3, hspace=0.1, wspace=0.1) # 显著减小间距
88
 
89
  # 设置字体和样式
90
  plt.rcParams['font.family'] = 'sans-serif'
91
  plt.rcParams['font.sans-serif'] = ['SimHei'] # 中文字体
92
 
93
  # 计算适合的字体大小
94
+ base_fontsize = min(45, 220 / rows) # 增加基础字体大小
95
 
96
  # 填充数据
97
  for idx, (hall, end_time) in enumerate(data.values):
98
+ row = idx // 3
99
+ col = idx % 3
100
+
101
+ # 创建子图
102
+ ax = plt.subplot(gs[row, col])
103
 
104
  # 设置更深的边框颜色
105
  for spine in ax.spines.values():
 
114
  ha='center',
115
  va='center')
116
 
117
+ # 设置更小的内边距
118
+ ax.set_xlim(-0.02, 1.02)
119
+ ax.set_ylim(-0.02, 1.02)
120
+
121
  # 移除坐标轴
122
  ax.set_xticks([])
123
  ax.set_yticks([])
124
 
 
 
 
125
  # 将图表转换为 base64 字符串
126
  buffer = io.BytesIO()
127
  plt.savefig(buffer, format='png', bbox_inches='tight', pad_inches=0.05) # 减小边距