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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -20
app.py CHANGED
@@ -76,30 +76,19 @@ def create_print_layout(data, title):
76
  if data.empty:
77
  return None
78
 
79
- # 设置 A5 横向尺寸(单位:英寸)
80
- fig = plt.figure(figsize=(8.27, 5.83), 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) + 3) // 4 # 向上取整除法
87
- gs = gridspec.GridSpec(rows, 4, 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 // 4
99
- col = idx % 4
100
-
101
- # 创建子图
102
- ax = plt.subplot(gs[row, col])
103
 
104
  # 设置更深的边框颜色
105
  for spine in ax.spines.values():
@@ -114,14 +103,13 @@ def create_print_layout(data, title):
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) # 减小边距
@@ -161,4 +149,4 @@ if uploaded_file:
161
  if part2_image:
162
  st.image(part2_image)
163
  else:
164
- st.info("夜班部分没有数据")
 
76
  if data.empty:
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
  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) # 减小边距
 
149
  if part2_image:
150
  st.image(part2_image)
151
  else:
152
+ st.info("夜班部分没有数据")