From 5a5109b1a619fe9c4cde7442285f282bde2f9be0 Mon Sep 17 00:00:00 2001 From: DXC Date: Mon, 22 Jun 2026 17:48:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(viz=5Freports):=20plot=5Fscatter=5Ftrue=5Fv?= =?UTF-8?q?s=5Fpred=20NaN=20=E5=AE=B9=E9=94=99=20+=20subplots=5Fadjust=20?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=20tight=5Flayout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/postprocessing/visualization_reports.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/postprocessing/visualization_reports.py b/src/postprocessing/visualization_reports.py index 65b5a78..2ce00c7 100644 --- a/src/postprocessing/visualization_reports.py +++ b/src/postprocessing/visualization_reports.py @@ -81,7 +81,11 @@ class WaterQualityVisualization: 保存的文件路径 """ fig, ax = plt.subplots(figsize=(10, 8)) - + + # 强制处理 NaN + y_true = np.nan_to_num(y_true, nan=0.0) + y_pred = np.nan_to_num(y_pred, nan=0.0) + # 计算所有数据的R²和RMSE from sklearn.metrics import r2_score, mean_squared_error, mean_absolute_error @@ -133,7 +137,7 @@ class WaterQualityVisualization: ax.set_xlabel(f'真实值 ({target_name})', fontsize=14, fontweight='bold') ax.set_ylabel(f'预测值 ({target_name})', fontsize=14, fontweight='bold') ax.set_title(f'{target_name} - 真实值 vs 预测值', fontsize=16, fontweight='bold') - ax.legend(loc='upper left', fontsize=11, bbox_to_anchor=(1.02, 1), borderaxespad=0) + ax.legend(loc='upper left', fontsize=11, bbox_to_anchor=(1.05, 1), borderaxespad=0) ax.grid(True, alpha=0.3) # 添加指标文本框 @@ -141,7 +145,7 @@ class WaterQualityVisualization: verticalalignment='top', bbox=dict(boxstyle='round', facecolor='wheat', alpha=0.8), fontsize=10) - plt.tight_layout() + plt.subplots_adjust(right=0.85) # 保存图片 if output_path is None: