cwadayi commited on
Commit
4a31c97
·
verified ·
1 Parent(s): 9e06a66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -2,6 +2,12 @@ import gradio as gr
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
 
 
 
 
 
 
 
5
  # --- 核心計算與繪圖函數 ---
6
  def plot_seismic_refraction(v1, v2, h, x_max):
7
  """
@@ -20,7 +26,7 @@ def plot_seismic_refraction(v1, v2, h, x_max):
20
  # 物理條件檢查:折射必須 V2 > V1
21
  if v2 <= v1:
22
  # 建立一個空的圖表並顯示錯誤訊息
23
- fig, ax = plt.subplots()
24
  ax.text(0.5, 0.5, '錯誤:V2 必須大於 V1 才能產生臨界折射!\n(Error: V2 must be greater than V1 for critical refraction to occur.)',
25
  ha='center', va='center', fontsize=12, color='red')
26
  ax.set_xlabel("與震源的距離 (Distance, m)")
@@ -154,5 +160,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
154
  )
155
 
156
  if __name__ == "__main__":
157
- demo.launch()
158
-
 
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
 
5
+ # 解決 Matplotlib 中文亂碼問題 (關鍵修正)
6
+ # 指定使用 Noto Sans CJK TC 字體,這是我們透過 packages.txt 安裝的
7
+ plt.rcParams['font.sans-serif'] = ['Noto Sans CJK TC', 'sans-serif']
8
+ # 正常顯示負號,以防未來有需要
9
+ plt.rcParams['axes.unicode_minus'] = False
10
+
11
  # --- 核心計算與繪圖函數 ---
12
  def plot_seismic_refraction(v1, v2, h, x_max):
13
  """
 
26
  # 物理條件檢查:折射必須 V2 > V1
27
  if v2 <= v1:
28
  # 建立一個空的圖表並顯示錯誤訊息
29
+ fig, ax = plt.subplots(figsize=(10, 6))
30
  ax.text(0.5, 0.5, '錯誤:V2 必須大於 V1 才能產生臨界折射!\n(Error: V2 must be greater than V1 for critical refraction to occur.)',
31
  ha='center', va='center', fontsize=12, color='red')
32
  ax.set_xlabel("與震源的距離 (Distance, m)")
 
160
  )
161
 
162
  if __name__ == "__main__":
163
+ demo.launch()