ソースを参照

在画图时带上余票的注释

node04 4 日 前
コミット
4409c850b3
1 ファイル変更21 行追加8 行削除
  1. 21 8
      data_loader.py

+ 21 - 8
data_loader.py

@@ -624,9 +624,22 @@ def plot_c12_trend(df, output_dir="."):
             markeredgewidth=2,
         )
         
-        # 添加注释 (小时数, 价格)
-        for _, row in change_points.iterrows():
-            text = f"({row['hours_until_departure']}, {row['adult_total_price']})"
+        # 添加注释 (小时数, 价格, 余票)
+        # 点密集时自动抽样,避免文字严重重叠
+        n_points = len(change_points)
+        max_labels = 30
+        step = max(1, int(np.ceil(n_points / max_labels)))
+        label_points = change_points.iloc[::step].copy()
+
+        # 确保最后一个点始终有注释
+        if n_points > 0 and label_points.index[-1] != change_points.index[-1]:
+            label_points = pd.concat([label_points, change_points.tail(1)])
+
+        rotation_angle = 45 if n_points > max_labels else 25
+        label_fontsize = 4 if n_points > max_labels else 5
+
+        for _, row in label_points.iterrows():
+            text = f"({row['hours_until_departure']}, {row['adult_total_price']}, {row['seats_remaining']})"
             plt.annotate(
                 text,
                 xy=(row['update_hour'], row['adult_total_price']),
@@ -634,10 +647,10 @@ def plot_c12_trend(df, output_dir="."):
                 textcoords="offset points",
                 ha='left',
                 va='center',
-                fontsize=5,  # 字体稍小
+                fontsize=label_fontsize,
                 color='gray',
                 alpha=0.8,
-                rotation=25,
+                rotation=rotation_angle,
             )
 
     # 自动优化日期显示
@@ -1203,10 +1216,10 @@ if __name__ == "__main__":
     date_begin = "2026-04-21"
     date_end = datetime.today().strftime("%Y-%m-%d")
 
-    flight_route_list = vj_flight_route_list_nothot[:]  # 热门 vj_flight_route_list_hot  冷门 vj_flight_route_list_nothot
+    flight_route_list = vj_flight_route_list_hot[:]  # 热门 vj_flight_route_list_hot  冷门 vj_flight_route_list_nothot
     # flight_route_list = ["SGN-NGO"]  # 测试段
-    table_name = CLEAN_VJ_NOTHOT_NEAR_INFO_TAB  # 热门 CLEAN_VJ_HOT_NEAR_INFO_TAB  冷门 CLEAN_VJ_NOTHOT_NEAR_INFO_TAB
-    is_hot = 0   # 1 热门 0 冷门
+    table_name = CLEAN_VJ_HOT_NEAR_INFO_TAB  # 热门 CLEAN_VJ_HOT_NEAR_INFO_TAB  冷门 CLEAN_VJ_NOTHOT_NEAR_INFO_TAB
+    is_hot = 1   # 1 热门 0 冷门
     group_size = 1
     chunks = chunk_list_with_index(flight_route_list, group_size)