Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,8 @@ st.markdown("""
|
|
| 16 |
<style>
|
| 17 |
/* CSS แก้ปัญหาการสั่นของหน้าจอ */
|
| 18 |
.stApp { transition: none !important; }
|
|
|
|
|
|
|
| 19 |
html, body, [class*="st-"] {
|
| 20 |
font-size: 18px;
|
| 21 |
}
|
|
@@ -92,7 +94,8 @@ kspace_bg_image = format_kspace_display(kspace_raw)
|
|
| 92 |
|
| 93 |
def get_image_from_plot(fig):
|
| 94 |
buf = io.BytesIO()
|
| 95 |
-
|
|
|
|
| 96 |
plt.close(fig)
|
| 97 |
buf.seek(0)
|
| 98 |
return Image.open(buf)
|
|
@@ -104,27 +107,27 @@ def draw_kspace_diagram():
|
|
| 104 |
rect = plt.Rectangle((-1, -1), 2, 2, fill=False, edgecolor='black', lw=3)
|
| 105 |
ax.add_patch(rect)
|
| 106 |
|
| 107 |
-
# วาดแกนลูกศรตัดกันตรงกลาง
|
| 108 |
-
ax.annotate('', xy=(0.
|
| 109 |
-
ax.annotate('', xy=(0, 0.
|
| 110 |
|
| 111 |
-
# ตัวอักษรบอกทิศทาง +kx, -kx, +ky, -ky (
|
| 112 |
ax.text(1.1, 0, '+kx', fontsize=20, fontweight='bold', va='center')
|
| 113 |
-
ax.text(-1.
|
| 114 |
ax.text(0, 1.1, '+ky', fontsize=20, fontweight='bold', ha='center')
|
| 115 |
ax.text(0, -1.1, '-ky', fontsize=20, fontweight='bold', ha='center', va='top')
|
| 116 |
|
| 117 |
-
# Label บอกชื่อแกน
|
| 118 |
# Frequency axis ด้านล่าง
|
| 119 |
-
ax.annotate('', xy=(
|
| 120 |
-
ax.text(0, -1.
|
| 121 |
|
| 122 |
# Phase axis ด้านซ้าย
|
| 123 |
-
ax.annotate('', xy=(-1.
|
| 124 |
-
ax.text(-1.
|
| 125 |
|
| 126 |
-
ax.set_xlim(-
|
| 127 |
-
ax.set_ylim(-
|
| 128 |
ax.axis('off')
|
| 129 |
|
| 130 |
plt.tight_layout()
|
|
@@ -323,7 +326,6 @@ with col_main:
|
|
| 323 |
|
| 324 |
st.progress((st.session_state.fill_step + 1) / total_anim_steps)
|
| 325 |
|
| 326 |
-
# แก้ปัญหาหน้าจอโหลดกระตุก โดยใช้ st.empty() คุมทีละภาพแทนที่จะคุมทั้ง Container
|
| 327 |
col_anim1, col_anim2 = st.columns([1, 1])
|
| 328 |
with col_anim1:
|
| 329 |
img1_ph = st.empty()
|
|
|
|
| 16 |
<style>
|
| 17 |
/* CSS แก้ปัญหาการสั่นของหน้าจอ */
|
| 18 |
.stApp { transition: none !important; }
|
| 19 |
+
/* กำหนดความสูงตายตัวให้กับ container กราฟ */
|
| 20 |
+
.fixed-height-chart { min-height: 500px; display: flex; align-items: center; justify-content: center; }
|
| 21 |
html, body, [class*="st-"] {
|
| 22 |
font-size: 18px;
|
| 23 |
}
|
|
|
|
| 94 |
|
| 95 |
def get_image_from_plot(fig):
|
| 96 |
buf = io.BytesIO()
|
| 97 |
+
# ลบ bbox_inches='tight' ออกเพื่อไม่ให้รูปภาพเปลี่ยนขนาดไปมา (แก้อาการสั่น)
|
| 98 |
+
plt.savefig(buf, format='png', dpi=100)
|
| 99 |
plt.close(fig)
|
| 100 |
buf.seek(0)
|
| 101 |
return Image.open(buf)
|
|
|
|
| 107 |
rect = plt.Rectangle((-1, -1), 2, 2, fill=False, edgecolor='black', lw=3)
|
| 108 |
ax.add_patch(rect)
|
| 109 |
|
| 110 |
+
# วาดแกนลูกศรตัดกันตรงกลาง (อยู่ภายในกรอบ)
|
| 111 |
+
ax.annotate('', xy=(0.9, 0), xytext=(-0.9, 0), arrowprops=dict(arrowstyle='<|-|>', color='black', lw=2))
|
| 112 |
+
ax.annotate('', xy=(0, 0.9), xytext=(0, -0.9), arrowprops=dict(arrowstyle='<|-|>', color='black', lw=2))
|
| 113 |
|
| 114 |
+
# ตัวอักษรบอกทิศทาง +kx, -kx, +ky, -ky (อยู่นอกกรอบ)
|
| 115 |
ax.text(1.1, 0, '+kx', fontsize=20, fontweight='bold', va='center')
|
| 116 |
+
ax.text(-1.1, 0, '-kx', fontsize=20, fontweight='bold', va='center', ha='right')
|
| 117 |
ax.text(0, 1.1, '+ky', fontsize=20, fontweight='bold', ha='center')
|
| 118 |
ax.text(0, -1.1, '-ky', fontsize=20, fontweight='bold', ha='center', va='top')
|
| 119 |
|
| 120 |
+
# Label บอกชื่อแกนพร้อมลูกศร
|
| 121 |
# Frequency axis ด้านล่าง
|
| 122 |
+
ax.annotate('', xy=(0.9, -1.4), xytext=(-0.9, -1.4), arrowprops=dict(arrowstyle='<|-|>', color='black', lw=4))
|
| 123 |
+
ax.text(0, -1.5, 'kx (Frequency)', ha='center', va='top', fontsize=16, fontweight='bold')
|
| 124 |
|
| 125 |
# Phase axis ด้านซ้าย
|
| 126 |
+
ax.annotate('', xy=(-1.5, 0.9), xytext=(-1.5, -0.9), arrowprops=dict(arrowstyle='<|-|>', color='black', lw=4))
|
| 127 |
+
ax.text(-1.6, 0, 'ky (Phase)', ha='right', va='center', rotation=90, fontsize=16, fontweight='bold')
|
| 128 |
|
| 129 |
+
ax.set_xlim(-2.0, 1.5)
|
| 130 |
+
ax.set_ylim(-2.0, 1.5)
|
| 131 |
ax.axis('off')
|
| 132 |
|
| 133 |
plt.tight_layout()
|
|
|
|
| 326 |
|
| 327 |
st.progress((st.session_state.fill_step + 1) / total_anim_steps)
|
| 328 |
|
|
|
|
| 329 |
col_anim1, col_anim2 = st.columns([1, 1])
|
| 330 |
with col_anim1:
|
| 331 |
img1_ph = st.empty()
|