Lashtw commited on
Commit
f0696dc
·
verified ·
1 Parent(s): 6d50125

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -55,11 +55,13 @@ def create_radar_chart(df, selected_rows, selected_columns, student_name=""):
55
  ),
56
  marker=dict(opacity=0.5)
57
  ))
 
58
  if selected_columns:
59
  max_value = df[selected_columns].values.max() * 1.1
60
  else:
61
  max_value = 100
62
 
 
63
  fig.update_layout(
64
  polar=dict(
65
  radialaxis=dict(
@@ -69,7 +71,8 @@ def create_radar_chart(df, selected_rows, selected_columns, student_name=""):
69
  ),
70
  angularaxis=dict(
71
  tickfont=dict(size=16, color='black', family="Microsoft JhengHei, Noto Sans CJK, Arial")
72
- )
 
73
  ),
74
  showlegend=True,
75
  legend=dict(
@@ -101,20 +104,27 @@ def apply_font_to_all_text(fig):
101
  trace.textfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
102
  if hasattr(trace, 'marker') and hasattr(trace.marker, 'textfont'):
103
  trace.marker.textfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
 
 
104
  fig.update_layout(
105
  font=dict(
106
  family="Microsoft JhengHei, Noto Sans CJK, Arial"
107
  )
108
  )
109
 
 
110
  if hasattr(fig, 'layout') and hasattr(fig.layout, 'xaxis'):
111
  fig.layout.xaxis.tickfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
112
  if hasattr(fig, 'layout') and hasattr(fig.layout, 'yaxis'):
113
  fig.layout.yaxis.tickfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
 
 
114
  if hasattr(fig, 'layout') and hasattr(fig.layout, 'polar') and hasattr(fig.layout.polar, 'radialaxis'):
115
  fig.layout.polar.radialaxis.tickfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
 
116
  if hasattr(fig, 'layout') and hasattr(fig.layout, 'polar') and hasattr(fig.layout.polar, 'angularaxis'):
117
  fig.layout.polar.angularaxis.tickfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
 
118
 
119
  return fig
120
 
@@ -164,7 +174,8 @@ def main():
164
  continue
165
  fig = create_radar_chart(df, comparison_items + [student], selected_columns,
166
  student_name=student) # 傳遞學生姓名
167
- fig = apply_font_to_all_text(fig) # 確保套用字型設定
 
168
  image_bytes[student] = create_image_bytes(fig) # 儲存位元組
169
 
170
  cols = st.columns(3) # 排成三列
 
55
  ),
56
  marker=dict(opacity=0.5)
57
  ))
58
+
59
  if selected_columns:
60
  max_value = df[selected_columns].values.max() * 1.1
61
  else:
62
  max_value = 100
63
 
64
+ # 修改這部分,設定 polar 的字型
65
  fig.update_layout(
66
  polar=dict(
67
  radialaxis=dict(
 
71
  ),
72
  angularaxis=dict(
73
  tickfont=dict(size=16, color='black', family="Microsoft JhengHei, Noto Sans CJK, Arial")
74
+ ),
75
+ font=dict(family="Microsoft JhengHei, Noto Sans CJK, Arial") # 在 polar 區塊設定字型
76
  ),
77
  showlegend=True,
78
  legend=dict(
 
104
  trace.textfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
105
  if hasattr(trace, 'marker') and hasattr(trace.marker, 'textfont'):
106
  trace.marker.textfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
107
+
108
+ # 將字型設定到 layout
109
  fig.update_layout(
110
  font=dict(
111
  family="Microsoft JhengHei, Noto Sans CJK, Arial"
112
  )
113
  )
114
 
115
+ # 設定到軸
116
  if hasattr(fig, 'layout') and hasattr(fig.layout, 'xaxis'):
117
  fig.layout.xaxis.tickfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
118
  if hasattr(fig, 'layout') and hasattr(fig.layout, 'yaxis'):
119
  fig.layout.yaxis.tickfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
120
+
121
+ # 設定到極座標軸
122
  if hasattr(fig, 'layout') and hasattr(fig.layout, 'polar') and hasattr(fig.layout.polar, 'radialaxis'):
123
  fig.layout.polar.radialaxis.tickfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
124
+ fig.layout.polar.radialaxis.titlefont.family = "Microsoft JhengHei, Noto Sans CJK, Arial" # 極座標 title
125
  if hasattr(fig, 'layout') and hasattr(fig.layout, 'polar') and hasattr(fig.layout.polar, 'angularaxis'):
126
  fig.layout.polar.angularaxis.tickfont.family = "Microsoft JhengHei, Noto Sans CJK, Arial"
127
+ fig.layout.polar.angularaxis.titlefont.family = "Microsoft JhengHei, Noto Sans CJK, Arial" # 極座標 title
128
 
129
  return fig
130
 
 
174
  continue
175
  fig = create_radar_chart(df, comparison_items + [student], selected_columns,
176
  student_name=student) # 傳遞學生姓名
177
+
178
+ fig = apply_font_to_all_text(fig) # 確保套用字型設定
179
  image_bytes[student] = create_image_bytes(fig) # 儲存位元組
180
 
181
  cols = st.columns(3) # 排成三列