p1: fig
This commit is contained in:
@@ -515,7 +515,7 @@ def print_summary(df: pd.DataFrame):
|
||||
|
||||
def plot_three_scenarios_comparison(
|
||||
year_min: float = 100,
|
||||
year_max: float = 300,
|
||||
year_max: float = 250,
|
||||
save_path: str = '/Volumes/Files/code/mm/20260130_b/three_scenarios_comparison.png'
|
||||
):
|
||||
"""
|
||||
@@ -579,74 +579,45 @@ def plot_three_scenarios_comparison(
|
||||
else:
|
||||
combined_energy.append(np.nan)
|
||||
|
||||
# 创建图表
|
||||
fig, ax = plt.subplots(figsize=(14, 8))
|
||||
# 创建图表 - 使用0.618黄金比例,缩小尺寸以放大字体
|
||||
fig_width = 8
|
||||
fig_height = fig_width * 0.618
|
||||
fig, ax = plt.subplots(figsize=(fig_width, fig_height))
|
||||
|
||||
# 中偏低饱和度配色
|
||||
color_rocket = '#B85450' # 暗砖红色
|
||||
color_elevator = '#5B8266' # 灰绿色
|
||||
color_combined = '#4A6FA5' # 灰蓝色
|
||||
|
||||
# 绘制三条折线
|
||||
ax.plot(years, rocket_energy, 'r-', linewidth=2.5, label='Rocket Only', marker='', markersize=4)
|
||||
ax.plot(years, elevator_energy, 'g-', linewidth=2.5, label='Elevator Only', marker='', markersize=4)
|
||||
ax.plot(years, combined_energy, 'b-', linewidth=2.5, label='Combined (Elevator + Rocket)', marker='', markersize=4)
|
||||
ax.plot(years, rocket_energy, color=color_rocket, linewidth=2.5, label='Rocket Only', marker='', markersize=4)
|
||||
ax.plot(years, elevator_energy, color=color_elevator, linewidth=2.5, label='Elevator Only', marker='', markersize=4)
|
||||
ax.plot(years, combined_energy, color=color_combined, linewidth=2.5, label='Combined (Elevator + Rocket)', marker='', markersize=4)
|
||||
|
||||
# 标记关键时间点
|
||||
ax.axvline(x=combined_min_years, color='blue', linestyle=':', alpha=0.7, linewidth=1.5)
|
||||
ax.axvline(x=elevator_only_min_years, color='green', linestyle=':', alpha=0.7, linewidth=1.5)
|
||||
ax.axvline(x=rocket_only_min_years, color='red', linestyle=':', alpha=0.7, linewidth=1.5)
|
||||
ax.axvline(x=combined_min_years, color=color_combined, linestyle=':', alpha=0.7, linewidth=1.5)
|
||||
ax.axvline(x=elevator_only_min_years, color=color_elevator, linestyle=':', alpha=0.7, linewidth=1.5)
|
||||
ax.axvline(x=rocket_only_min_years, color=color_rocket, linestyle=':', alpha=0.7, linewidth=1.5)
|
||||
|
||||
# 添加标注
|
||||
y_pos = ax.get_ylim()[1] * 0.95
|
||||
# 添加标注 - 使用低饱和度背景色,避免遮挡曲线
|
||||
y_max = ax.get_ylim()[1]
|
||||
ax.annotate(f'Combined\nMin: {combined_min_years:.0f}y',
|
||||
xy=(combined_min_years, y_pos), fontsize=9, ha='center',
|
||||
bbox=dict(boxstyle='round', facecolor='lightblue', alpha=0.8))
|
||||
xy=(combined_min_years, y_max * 0.55), fontsize=9, ha='center',
|
||||
bbox=dict(boxstyle='round', facecolor='#C5D5E8', edgecolor=color_combined, alpha=0.9))
|
||||
ax.annotate(f'Elevator\nMin: {elevator_only_min_years:.0f}y',
|
||||
xy=(elevator_only_min_years, y_pos * 0.85), fontsize=9, ha='center',
|
||||
bbox=dict(boxstyle='round', facecolor='lightgreen', alpha=0.8))
|
||||
xy=(elevator_only_min_years, y_max * 0.72), fontsize=9, ha='center',
|
||||
bbox=dict(boxstyle='round', facecolor='#C8DBC8', edgecolor=color_elevator, alpha=0.9))
|
||||
ax.annotate(f'Rocket\nMin: {rocket_only_min_years:.0f}y',
|
||||
xy=(rocket_only_min_years, y_pos * 0.75), fontsize=9, ha='center',
|
||||
bbox=dict(boxstyle='round', facecolor='lightsalmon', alpha=0.8))
|
||||
xy=(rocket_only_min_years, y_max * 0.55), fontsize=9, ha='center',
|
||||
bbox=dict(boxstyle='round', facecolor='#E8C8C5', edgecolor=color_rocket, alpha=0.9))
|
||||
|
||||
# 填充区域表示节能效果
|
||||
# Combined比Rocket节省的能量
|
||||
rocket_arr = np.array(rocket_energy)
|
||||
combined_arr = np.array(combined_energy)
|
||||
valid_mask = ~np.isnan(rocket_arr) & ~np.isnan(combined_arr)
|
||||
ax.fill_between(years[valid_mask], combined_arr[valid_mask], rocket_arr[valid_mask],
|
||||
alpha=0.2, color='purple', label='Energy saved by Combined vs Rocket')
|
||||
|
||||
ax.set_xlabel('Completion Time (years)', fontsize=13)
|
||||
ax.set_ylabel('Total Energy Consumption (PJ)', fontsize=13)
|
||||
ax.set_title('Moon Colony Construction: Energy vs Completion Time\n'
|
||||
'(100 Million Metric Tons Payload Comparison)', fontsize=15)
|
||||
ax.legend(loc='upper right', fontsize=11)
|
||||
ax.set_xlabel('Completion Time (years)', fontsize=11)
|
||||
ax.set_ylabel('Total Energy Consumption (PJ)', fontsize=11)
|
||||
ax.legend(loc='upper left', fontsize=9)
|
||||
ax.grid(True, alpha=0.3)
|
||||
ax.set_xlim(year_min, year_max)
|
||||
|
||||
# 添加数据表格
|
||||
# 选择几个关键年份的数据
|
||||
key_years = [110, 150, 186, 220, 250]
|
||||
table_data = []
|
||||
for ky in key_years:
|
||||
idx = np.argmin(np.abs(years - ky))
|
||||
table_data.append([
|
||||
f'{ky}',
|
||||
f'{combined_energy[idx]:.0f}' if not np.isnan(combined_energy[idx]) else 'N/A',
|
||||
f'{elevator_energy[idx]:.0f}' if not np.isnan(elevator_energy[idx]) else 'N/A',
|
||||
f'{rocket_energy[idx]:.0f}' if not np.isnan(rocket_energy[idx]) else 'N/A',
|
||||
])
|
||||
|
||||
# 在图表下方添加表格
|
||||
table = ax.table(
|
||||
cellText=table_data,
|
||||
colLabels=['Year', 'Combined (PJ)', 'Elevator (PJ)', 'Rocket (PJ)'],
|
||||
loc='bottom',
|
||||
bbox=[0.15, -0.25, 0.7, 0.18],
|
||||
cellLoc='center'
|
||||
)
|
||||
table.auto_set_font_size(False)
|
||||
table.set_fontsize(10)
|
||||
table.scale(1, 1.5)
|
||||
|
||||
# 调整布局给表格留空间
|
||||
plt.subplots_adjust(bottom=0.25)
|
||||
plt.tight_layout()
|
||||
|
||||
plt.savefig(save_path, dpi=150, bbox_inches='tight')
|
||||
print(f"\n三方案对比图已保存至: {save_path}")
|
||||
@@ -700,6 +671,6 @@ if __name__ == "__main__":
|
||||
print(f"{name:<25} {data['years']:>12.0f} {data['energy_PJ']:>15.0f} {savings:>17.0f}%")
|
||||
print("=" * 90)
|
||||
|
||||
# 生成三方案对比折线图 (100-300年)
|
||||
print("\n\n正在生成三方案对比折线图 (100-300年)...")
|
||||
plot_three_scenarios_comparison(year_min=100, year_max=300)
|
||||
# 生成三方案对比折线图 (100-250年)
|
||||
print("\n\n正在生成三方案对比折线图 (100-250年)...")
|
||||
plot_three_scenarios_comparison(year_min=100, year_max=250)
|
||||
|
||||
Reference in New Issue
Block a user