ADTK可视化报错:'seaborn-whitegrid'非有效Matplotlib样式
解决ADTK可视化时Matplotlib样式报错问题
问题原因
ADTK的plot函数默认使用旧版Matplotlib的seaborn样式名seaborn-whitegrid,但Matplotlib 3.7及以上版本中,seaborn相关样式统一添加了v0_8后缀(如seaborn-v0_8-whitegrid),导致样式查找失败抛出OSError。Jupyter环境能正常运行是因为其依赖的Matplotlib版本低于3.7,或样式注册逻辑不同。
解决方案
方法1:降级Matplotlib到兼容版本
将Matplotlib降至3.6.x版本,适配ADTK默认的样式命名:
pip install matplotlib==3.6.3
方法2:显式指定新版样式名
在调用ADTK的plot函数时,通过style参数指定新版样式:
plot(data_valid, anomaly=anomalies, ts_linewidth=1, ts_markersize=3, anomaly_markersize=3, anomaly_color='red', anomaly_tag="marker", style="seaborn-v0_8-whitegrid");
也可以在代码开头全局设置Matplotlib样式,避免每次调用都指定:
import matplotlib.pyplot as plt plt.style.use("seaborn-v0_8-whitegrid")
方法3:升级ADTK到最新版本
尝试升级ADTK,看是否已适配新版Matplotlib的样式命名:
pip install --upgrade adtk
(注:此方法有效性取决于ADTK的维护进度,优先推荐前两种方法)
内容的提问来源于stack exchange,提问作者Elias Rudsbråten
相关产品推荐
相关产品推荐

