File size: 656 Bytes
e40db0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Matplotlib 显示控制(CI 无头环境默认不弹窗)。"""

from __future__ import annotations

import os
from typing import Optional


def should_show_plots(explicit: Optional[bool] = None) -> bool:
    if explicit is not None:
        return explicit
    return os.environ.get("FLORENCE_FORGE_SHOW_PLOTS", "").lower() in (
        "1",
        "true",
        "yes",
    )


def finalize_matplotlib_figure(show: Optional[bool] = None) -> None:
    """保存后关闭或显示图形;默认关闭以避免阻塞 CI。"""
    import matplotlib.pyplot as plt

    if should_show_plots(show):
        plt.show()
    else:
        plt.close("all")