jeff7522553
commited on
Commit
·
d9b1c0e
1
Parent(s):
8fe85e5
更新箱型圖
Browse files
app.py
CHANGED
|
@@ -182,7 +182,7 @@ def calculate_statistics(data_str):
|
|
| 182 |
fig.suptitle('Statistical analysis visualization', fontsize=16, fontweight='bold')
|
| 183 |
|
| 184 |
# 1. 直方圖
|
| 185 |
-
axes[0].hist(data, bins=min(
|
| 186 |
axes[0].axvline(arithmetic_mean, color='red', linestyle='--', linewidth=2, label=f'Mean: {arithmetic_mean:.2f}')
|
| 187 |
axes[0].axvline(median, color='green', linestyle='--', linewidth=2, label=f'Median: {median:.2f}')
|
| 188 |
axes[0].set_title('Histograms and Central Tendency', fontsize=14)
|
|
@@ -192,19 +192,28 @@ def calculate_statistics(data_str):
|
|
| 192 |
axes[0].grid(True, alpha=0.3)
|
| 193 |
|
| 194 |
# 2. 箱形圖
|
| 195 |
-
box_data = axes[1].boxplot(data, patch_artist=True, widths=0.6)
|
| 196 |
box_data['boxes'][0].set_facecolor('lightblue')
|
| 197 |
box_data['boxes'][0].set_alpha(0.7)
|
| 198 |
axes[1].set_title('Box Plot (Quartiles)', fontsize=14)
|
| 199 |
-
axes[1].
|
| 200 |
axes[1].grid(True, alpha=0.3)
|
| 201 |
|
| 202 |
# 添加四分位數標籤
|
| 203 |
-
axes[1].text(1.
|
| 204 |
-
axes[1].text(1.
|
| 205 |
-
axes[1].text(1.
|
| 206 |
-
axes[1].text(
|
| 207 |
-
axes[1].text(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
plt.tight_layout()
|
| 210 |
|
|
@@ -251,8 +260,8 @@ def create_interface():
|
|
| 251 |
with gr.Row():
|
| 252 |
n_generate = gr.Slider(
|
| 253 |
minimum=10,
|
| 254 |
-
maximum=
|
| 255 |
-
value=
|
| 256 |
step=10,
|
| 257 |
label="資料點數 (n)"
|
| 258 |
)
|
|
@@ -287,8 +296,8 @@ def create_interface():
|
|
| 287 |
gr.Markdown("#### 📈 分佈形狀參數")
|
| 288 |
with gr.Row():
|
| 289 |
target_skew = gr.Slider(
|
| 290 |
-
minimum=-
|
| 291 |
-
maximum=
|
| 292 |
value=0,
|
| 293 |
step=0.1,
|
| 294 |
label="目標偏態 (Skewness)",
|
|
@@ -296,8 +305,8 @@ def create_interface():
|
|
| 296 |
)
|
| 297 |
|
| 298 |
target_kurt = gr.Slider(
|
| 299 |
-
minimum=-
|
| 300 |
-
maximum=
|
| 301 |
value=0,
|
| 302 |
step=0.1,
|
| 303 |
label="目標峰態 (Kurtosis)",
|
|
|
|
| 182 |
fig.suptitle('Statistical analysis visualization', fontsize=16, fontweight='bold')
|
| 183 |
|
| 184 |
# 1. 直方圖
|
| 185 |
+
axes[0].hist(data, bins=min(100, len(set(data))), alpha=0.7, color='skyblue', edgecolor='black')
|
| 186 |
axes[0].axvline(arithmetic_mean, color='red', linestyle='--', linewidth=2, label=f'Mean: {arithmetic_mean:.2f}')
|
| 187 |
axes[0].axvline(median, color='green', linestyle='--', linewidth=2, label=f'Median: {median:.2f}')
|
| 188 |
axes[0].set_title('Histograms and Central Tendency', fontsize=14)
|
|
|
|
| 192 |
axes[0].grid(True, alpha=0.3)
|
| 193 |
|
| 194 |
# 2. 箱形圖
|
| 195 |
+
box_data = axes[1].boxplot(data, patch_artist=True, widths=0.6, vert=False, whis=[0, 100])
|
| 196 |
box_data['boxes'][0].set_facecolor('lightblue')
|
| 197 |
box_data['boxes'][0].set_alpha(0.7)
|
| 198 |
axes[1].set_title('Box Plot (Quartiles)', fontsize=14)
|
| 199 |
+
axes[1].set_xlabel('Value')
|
| 200 |
axes[1].grid(True, alpha=0.3)
|
| 201 |
|
| 202 |
# 添加四分位數標籤
|
| 203 |
+
# axes[1].text(q1, 1.1, f'Q1: {q1:.2f}', va='bottom', ha='center', fontsize=10)
|
| 204 |
+
# axes[1].text(median, 1.1, f'Q2: {median:.2f}', va='bottom', ha='center', fontsize=10, weight='bold')
|
| 205 |
+
# axes[1].text(q3, 1.1, f'Q3: {q3:.2f}', va='bottom', ha='center', fontsize=10)
|
| 206 |
+
# axes[1].text(np.min(data), 1.1, f'Min: {np.min(data):.2f}', va='bottom', ha='center', fontsize=9, alpha=0.7)
|
| 207 |
+
# axes[1].text(np.max(data), 1.1, f'Max: {np.max(data):.2f}', va='bottom', ha='center', fontsize=9, alpha=0.7)
|
| 208 |
+
|
| 209 |
+
y_offset = [1.05, 1.10, 1.15, 1.20, 1.25] # 依序往上排
|
| 210 |
+
axes[1].text(q1, y_offset[0], f'Q1: {q1:.2f}', ha='center', fontsize=10)
|
| 211 |
+
axes[1].text(median, y_offset[1], f'Q2: {median:.2f}', ha='center', fontsize=10, weight='bold')
|
| 212 |
+
axes[1].text(q3, y_offset[2], f'Q3: {q3:.2f}', ha='center', fontsize=10)
|
| 213 |
+
axes[1].text(np.min(data), y_offset[3], f'Min: {np.min(data):.2f}', ha='center', fontsize=9, alpha=0.7)
|
| 214 |
+
axes[1].text(np.max(data), y_offset[4], f'Max: {np.max(data):.2f}', ha='center', fontsize=9, alpha=0.7)
|
| 215 |
+
|
| 216 |
+
|
| 217 |
|
| 218 |
plt.tight_layout()
|
| 219 |
|
|
|
|
| 260 |
with gr.Row():
|
| 261 |
n_generate = gr.Slider(
|
| 262 |
minimum=10,
|
| 263 |
+
maximum=10000,
|
| 264 |
+
value=100,
|
| 265 |
step=10,
|
| 266 |
label="資料點數 (n)"
|
| 267 |
)
|
|
|
|
| 296 |
gr.Markdown("#### 📈 分佈形狀參數")
|
| 297 |
with gr.Row():
|
| 298 |
target_skew = gr.Slider(
|
| 299 |
+
minimum=-100.0,
|
| 300 |
+
maximum=100.0,
|
| 301 |
value=0,
|
| 302 |
step=0.1,
|
| 303 |
label="目標偏態 (Skewness)",
|
|
|
|
| 305 |
)
|
| 306 |
|
| 307 |
target_kurt = gr.Slider(
|
| 308 |
+
minimum=-100.0,
|
| 309 |
+
maximum=100.0,
|
| 310 |
value=0,
|
| 311 |
step=0.1,
|
| 312 |
label="目標峰態 (Kurtosis)",
|