import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.graph_objects as go
import plotly.express as px
from scipy.stats import gaussian_kde
import matplotlib.font_manager as fm
from matplotlib.colors import LinearSegmentedColormap
# 设置中文字体支持
plt.rcParams['font.sans-serif'] = ['SimHei', 'Arial Unicode MS', 'Microsoft YaHei', 'WenQuanYi Micro Hei']
plt.rcParams['axes.unicode_minus'] = False
# 设置随机种子,确保结果可复现
np.random.seed(42)
# 根据92.02%的高准确率生成模拟数据
# 总样本数
n_samples = 1000
# 正确样本比例 (92.02%)
correct_ratio = 0.9202
n_correct = int(n_samples * correct_ratio)
n_incorrect = n_samples - n_correct
# 生成预测不确定性数据
# 正确样本的不确定性较低,分布更集中
correct_uncertainty = np.random.normal(0.3, 0.15, n_correct)
# 错误样本的不确定性较高,分布更分散
incorrect_uncertainty = np.random.normal(1.2, 0.4, n_incorrect)
# 合并数据
uncertainty = np.concatenate([correct_uncertainty, incorrect_uncertainty])
correctness = np.concatenate([np.ones(n_correct), np.zeros(n_incorrect)])
# 添加峰高变异系数作为第三维度特征
cv_correct = np.random.normal(0.2, 0.1, n_correct) # 正确样本峰高变异系数较低
cv_incorrect = np.random.normal(0.6, 0.2, n_incorrect) # 错误样本峰高变异系数较高
cv = np.concatenate([cv_correct, cv_incorrect])
# 创建数据框
df = pd.DataFrame({
'uncertainty': uncertainty,
'correctness': correctness,
'result': ['正确' if c == 1 else '错误' for c in correctness],
'cv': cv
})
# 确保不确定性值为非负数
df['uncertainty'] = df['uncertainty'].clip(lower=0)
# 计算整体准确率
overall_accuracy = df['correctness'].mean()
print(f"模拟数据准确率: {overall_accuracy:.4f}")
# 创建自定义颜色映射
def create_green_cmap():
colors = ["#f0f9e8", "#bae4bc", "#7bccc4", "#2b8cbe"]
return LinearSegmentedColormap.from_list("green_cmap", colors)
# 保存所有图像的函数
def save_all_figures():
# 方案1:核密度估计(KDE)+ 统计摘要图
plt.figure(figsize=(12, 8))
kde = gaussian_kde(df['uncertainty'])
x_range = np.linspace(0, df['uncertainty'].max(), 200)
y_kde = kde(x_range)
# 计算统计指标
mean_uncert = df['uncertainty'].mean()
median_uncert = df['uncertainty'].median()
q25, q75 = np.percentile(df['uncertainty'], [25, 75])
std_uncert = df['uncertainty'].std()
plt.plot(x_range, y_kde, 'b-', linewidth=2, label='KDE分布')
plt.fill_between(x_range, y_kde, color='royalblue', alpha=0.2, label='分布区域')
# 标注统计指标
plt.axvline(mean_uncert, color='r', linestyle='--', label=f'均值: {mean_uncert:.2f}')
plt.axvline(median_uncert, color='g', linestyle=':', label=f'中位数: {median_uncert:.2f}')
plt.axvline(q25, color='purple', linestyle='-.', label=f'25%分位数: {q25:.2f}')
plt.axvline(q75, color='orange', linestyle='-.', label=f'75%分位数: {q75:.2f}')
plt.title(f'预测不确定性分布 (准确率: {overall_accuracy * 100:.2f}%)', fontsize=16, pad=20)
plt.xlabel('预测方差', fontsize=14)
plt.ylabel('概率密度', fontsize=14)
plt.legend(loc='upper right', fontsize=12)
plt.grid(alpha=0.2, linestyle='--')
# 添加统计信息框
stats_text = f'统计摘要:\n样本数: {n_samples}\n标准差: {std_uncert:.2f}\n最小值: {df["uncertainty"].min():.2f}\n最大值: {df["uncertainty"].max():.2f}'
plt.text(0.95, 0.95, stats_text,
transform=plt.gca().transAxes,
fontsize=12,
verticalalignment='top',
horizontalalignment='right',
bbox=dict(boxstyle='round', facecolor='white', alpha=0.8))
plt.tight_layout()
plt.savefig('1_kde_distribution.png', dpi=300, bbox_inches='tight')
plt.close()
# 方案2:分组小提琴图 + 抖动散点图
plt.figure(figsize=(12, 8))
sns.set_style("whitegrid")
# 创建自定义调色板
palette = {"正确": "#4caf50", "错误": "#f44336"}
# 绘制小提琴图
sns.violinplot(x='result', y='uncertainty', data=df, palette=palette,
inner='quartile', linewidth=2, saturation=0.8)
# 绘制散点图(带透明度)
sns.stripplot(x='result', y='uncertainty', data=df,
palette=palette, alpha=0.4, size=4, jitter=0.2)
# 添加中位数线
medians = df.groupby('result')['uncertainty'].median()
for i, category in enumerate(medians.index):
plt.hlines(medians[category], i - 0.3, i + 0.3, color='black', linestyles='dashed', linewidth=2)
plt.title(f'预测不确定性与结果分类 (准确率: {overall_accuracy * 100:.2f}%)', fontsize=16, pad=15)
plt.xlabel('预测结果', fontsize=14)
plt.ylabel('预测方差', fontsize=14)
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)
# 添加准确率注释
for i, category in enumerate(['正确', '错误']):
count = len(df[df['result'] == category])
percentage = count / len(df) * 100
plt.text(i, df['uncertainty'].max() + 0.1,
f'{count}个样本 ({percentage:.1f}%)',
ha='center', fontsize=12)
plt.ylim(-0.1, df['uncertainty'].max() + 0.3)
plt.tight_layout()
plt.savefig('2_violin_scatter.png', dpi=300, bbox_inches='tight')
plt.close()
# 方案3:热力图(分箱统计正确率)
bins = np.linspace(0, df['uncertainty'].max(), 11)
df['bin'] = pd.cut(df['uncertainty'], bins=bins, include_lowest=True, labels=False)
bin_stats = df.groupby(['bin', 'result']).size().unstack(fill_value=0)
bin_stats['accuracy'] = bin_stats['正确'] / bin_stats.sum(axis=1)
bin_stats['total_samples'] = bin_stats.sum(axis=1)
# 创建热力图数据
heatmap_data = bin_stats['accuracy'].values.reshape(-1, 1)
bin_labels = [f'{bins[i]:.2f}-{bins[i + 1]:.2f}' for i in range(len(bins) - 1)]
# 使用自定义绿色渐变颜色映射
cmap = create_green_cmap()
plt.figure(figsize=(12, 8))
plt.imshow(heatmap_data, cmap=cmap, aspect='auto', vmin=0, vmax=1)
# 添加颜色条
cbar = plt.colorbar()
cbar.set_label('正确率', fontsize=14)
# 添加单元格注释
for i in range(len(bin_labels)):
acc = heatmap_data[i, 0]
samples = bin_stats['total_samples'].iloc[i]
text_color = 'white' if acc < 0.6 else 'black'
plt.text(0, i, f'{acc:.2%}\n({samples}样本)',
ha='center', va='center',
color=text_color, fontsize=11, fontweight='bold')
# 设置坐标轴
plt.yticks(range(len(bin_labels)), bin_labels, fontsize=12)
plt.xticks([])
plt.ylabel('方差区间', fontsize=14)
plt.title(f'不同方差区间的预测正确率 (总体准确率: {overall_accuracy * 100:.2f}%)', fontsize=16, pad=20)
# 添加网格线
plt.grid(False)
for i in range(len(bin_labels) + 1):
plt.axhline(i - 0.5, color='white', linewidth=1)
plt.tight_layout()
plt.savefig('3_heatmap.png', dpi=300, bbox_inches='tight')
plt.close()
# 方案4:动态箱线图 + 错误率趋势线
fig = go.Figure()
# 添加箱线图
fig.add_trace(go.Box(
y=df['uncertainty'],
name='方差分布',
boxpoints='outliers',
marker=dict(color='#2196f3'),
line=dict(color='#0d47a1'),
fillcolor='rgba(33, 150, 243, 0.5)'
))
# 错误率趋势线
df['error'] = 1 - df['correctness']
x_fit = np.linspace(0, df['uncertainty'].max(), 100)
z = np.polyfit(df['uncertainty'], df['error'], 3)
p = np.poly1d(z)
y_fit = p(x_fit)
fig.add_trace(go.Scatter(
x=x_fit,
y=y_fit,
name='错误率趋势',
mode='lines',
line=dict(color='#e53935', width=3),
yaxis='y2'
))
fig.update_layout(
title=dict(
text=f'预测方差分布与错误率趋势 (准确率: {overall_accuracy * 100:.2f}%)',
font=dict(size=20, family="Microsoft YaHei"),
),
font=dict(family="Microsoft YaHei"),
xaxis=dict(
title='预测方差',
title_font=dict(family="Microsoft YaHei", size=14),
gridcolor='lightgray'
),
yaxis=dict(
title='方差值',
title_font=dict(family="Microsoft YaHei", size=14, color='#2196f3'),
tickfont=dict(color='#2196f3'),
gridcolor='rgba(33, 150, 243, 0.1)'
),
yaxis2=dict(
title='错误率',
title_font=dict(family="Microsoft YaHei", size=14, color='#e53935'),
tickfont=dict(color='#e53935'),
overlaying='y',
side='right',
range=[0, 1]
),
template='plotly_white',
width=1000,
height=700,
margin=dict(l=50, r=50, b=80, t=100),
legend=dict(
orientation="h",
yanchor="bottom",
y=1.02,
xanchor="right",
x=1,
font=dict(family="Microsoft YaHei")
),
hovermode="x unified"
)
# 添加注释
fig.add_annotation(
x=0.95,
y=0.95,
xref="paper",
yref="paper",
text=f"高方差区域错误率显著增加",
showarrow=False,
font=dict(size=14, color="#e53935", family="Microsoft YaHei"),
bgcolor="rgba(255, 255, 255, 0.8)"
)
fig.write_image('4_box_trend.png', scale=3)
# 方案5:三维密度图
fig = go.Figure()
# 添加正确样本
fig.add_trace(go.Scatter3d(
x=df[df['result'] == '正确']['uncertainty'],
y=df[df['result'] == '正确']['cv'],
z=df[df['result'] == '正确']['correctness'],
mode='markers',
name='正确',
marker=dict(
size=5,
color='#4caf50',
opacity=0.7
)
))
# 添加错误样本
fig.add_trace(go.Scatter3d(
x=df[df['result'] == '错误']['uncertainty'],
y=df[df['result'] == '错误']['cv'],
z=df[df['result'] == '错误']['correctness'],
mode='markers',
name='错误',
marker=dict(
size=7,
color='#f44336',
opacity=0.8,
symbol='diamond'
)
))
fig.update_layout(
title=dict(
text=f'三维预测不确定性分析 (准确率: {overall_accuracy * 100:.2f}%)',
font=dict(size=20, family="Microsoft YaHei"),
y=0.95
),
font=dict(family="Microsoft YaHei"),
scene=dict(
xaxis=dict(
title='预测方差',
title_font=dict(family="Microsoft YaHei", size=14)
),
yaxis=dict(
title='峰高变异系数',
title_font=dict(family="Microsoft YaHei", size=14)
),
zaxis=dict(
title='预测正确(1)/错误(0)',
title_font=dict(family="Microsoft YaHei", size=14)
),
camera=dict(
eye=dict(x=1.5, y=1.5, z=0.8)
)
),
width=1000,
height=800,
margin=dict(l=0, r=0, b=0, t=50),
legend=dict(
yanchor="top",
y=0.99,
xanchor="left",
x=0.01,
font=dict(family="Microsoft YaHei")
)
)
# 添加分类平面
fig.add_trace(go.Mesh3d(
x=[0, 2, 2, 0],
y=[0, 0, 1, 1],
z=[0.5, 0.5, 0.5, 0.5],
opacity=0.2,
color='gray',
name='分类平面'
))
fig.write_image('5_3d_density.png', scale=3)
print("所有图像已保存为PNG文件")
# 生成并保存所有图像
save_all_figures()
C:\python\py\.venv\Scripts\python.exe C:\python\py\3.py
模拟数据准确率: 0.9200
C:\python\py\3.py:113: FutureWarning:
Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.
C:\python\py\3.py:117: FutureWarning:
Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.
C:\python\py\3.py:140: UserWarning:
Glyph 27491 (\N{CJK UNIFIED IDEOGRAPH-6B63}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 30830 (\N{CJK UNIFIED IDEOGRAPH-786E}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 38169 (\N{CJK UNIFIED IDEOGRAPH-9519}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 35823 (\N{CJK UNIFIED IDEOGRAPH-8BEF}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 39044 (\N{CJK UNIFIED IDEOGRAPH-9884}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 27979 (\N{CJK UNIFIED IDEOGRAPH-6D4B}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 32467 (\N{CJK UNIFIED IDEOGRAPH-7ED3}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 26524 (\N{CJK UNIFIED IDEOGRAPH-679C}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 26041 (\N{CJK UNIFIED IDEOGRAPH-65B9}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 24046 (\N{CJK UNIFIED IDEOGRAPH-5DEE}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 19981 (\N{CJK UNIFIED IDEOGRAPH-4E0D}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 23450 (\N{CJK UNIFIED IDEOGRAPH-5B9A}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 24615 (\N{CJK UNIFIED IDEOGRAPH-6027}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 19982 (\N{CJK UNIFIED IDEOGRAPH-4E0E}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 31867 (\N{CJK UNIFIED IDEOGRAPH-7C7B}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 20934 (\N{CJK UNIFIED IDEOGRAPH-51C6}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 20010 (\N{CJK UNIFIED IDEOGRAPH-4E2A}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 26679 (\N{CJK UNIFIED IDEOGRAPH-6837}) missing from font(s) Arial.
C:\python\py\3.py:140: UserWarning:
Glyph 26412 (\N{CJK UNIFIED IDEOGRAPH-672C}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 27491 (\N{CJK UNIFIED IDEOGRAPH-6B63}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 30830 (\N{CJK UNIFIED IDEOGRAPH-786E}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 38169 (\N{CJK UNIFIED IDEOGRAPH-9519}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 35823 (\N{CJK UNIFIED IDEOGRAPH-8BEF}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 39044 (\N{CJK UNIFIED IDEOGRAPH-9884}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 27979 (\N{CJK UNIFIED IDEOGRAPH-6D4B}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 32467 (\N{CJK UNIFIED IDEOGRAPH-7ED3}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 26524 (\N{CJK UNIFIED IDEOGRAPH-679C}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 26041 (\N{CJK UNIFIED IDEOGRAPH-65B9}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 24046 (\N{CJK UNIFIED IDEOGRAPH-5DEE}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 19981 (\N{CJK UNIFIED IDEOGRAPH-4E0D}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 23450 (\N{CJK UNIFIED IDEOGRAPH-5B9A}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 24615 (\N{CJK UNIFIED IDEOGRAPH-6027}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 19982 (\N{CJK UNIFIED IDEOGRAPH-4E0E}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 31867 (\N{CJK UNIFIED IDEOGRAPH-7C7B}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 20934 (\N{CJK UNIFIED IDEOGRAPH-51C6}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 20010 (\N{CJK UNIFIED IDEOGRAPH-4E2A}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 26679 (\N{CJK UNIFIED IDEOGRAPH-6837}) missing from font(s) Arial.
C:\python\py\3.py:141: UserWarning:
Glyph 26412 (\N{CJK UNIFIED IDEOGRAPH-672C}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 27491 (\N{CJK UNIFIED IDEOGRAPH-6B63}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 30830 (\N{CJK UNIFIED IDEOGRAPH-786E}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 38169 (\N{CJK UNIFIED IDEOGRAPH-9519}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 35823 (\N{CJK UNIFIED IDEOGRAPH-8BEF}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 39044 (\N{CJK UNIFIED IDEOGRAPH-9884}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 27979 (\N{CJK UNIFIED IDEOGRAPH-6D4B}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 32467 (\N{CJK UNIFIED IDEOGRAPH-7ED3}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 26524 (\N{CJK UNIFIED IDEOGRAPH-679C}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 26041 (\N{CJK UNIFIED IDEOGRAPH-65B9}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 24046 (\N{CJK UNIFIED IDEOGRAPH-5DEE}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 19981 (\N{CJK UNIFIED IDEOGRAPH-4E0D}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 23450 (\N{CJK UNIFIED IDEOGRAPH-5B9A}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 24615 (\N{CJK UNIFIED IDEOGRAPH-6027}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 19982 (\N{CJK UNIFIED IDEOGRAPH-4E0E}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 31867 (\N{CJK UNIFIED IDEOGRAPH-7C7B}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 20934 (\N{CJK UNIFIED IDEOGRAPH-51C6}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 20010 (\N{CJK UNIFIED IDEOGRAPH-4E2A}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 26679 (\N{CJK UNIFIED IDEOGRAPH-6837}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 26412 (\N{CJK UNIFIED IDEOGRAPH-672C}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 26041 (\N{CJK UNIFIED IDEOGRAPH-65B9}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 24046 (\N{CJK UNIFIED IDEOGRAPH-5DEE}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 21306 (\N{CJK UNIFIED IDEOGRAPH-533A}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 38388 (\N{CJK UNIFIED IDEOGRAPH-95F4}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 19981 (\N{CJK UNIFIED IDEOGRAPH-4E0D}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 21516 (\N{CJK UNIFIED IDEOGRAPH-540C}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 30340 (\N{CJK UNIFIED IDEOGRAPH-7684}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 39044 (\N{CJK UNIFIED IDEOGRAPH-9884}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 27979 (\N{CJK UNIFIED IDEOGRAPH-6D4B}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 27491 (\N{CJK UNIFIED IDEOGRAPH-6B63}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 30830 (\N{CJK UNIFIED IDEOGRAPH-786E}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 24635 (\N{CJK UNIFIED IDEOGRAPH-603B}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 20307 (\N{CJK UNIFIED IDEOGRAPH-4F53}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 20934 (\N{CJK UNIFIED IDEOGRAPH-51C6}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 26679 (\N{CJK UNIFIED IDEOGRAPH-6837}) missing from font(s) Arial.
C:\python\py\3.py:185: UserWarning:
Glyph 26412 (\N{CJK UNIFIED IDEOGRAPH-672C}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 26041 (\N{CJK UNIFIED IDEOGRAPH-65B9}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 24046 (\N{CJK UNIFIED IDEOGRAPH-5DEE}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 21306 (\N{CJK UNIFIED IDEOGRAPH-533A}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 38388 (\N{CJK UNIFIED IDEOGRAPH-95F4}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 19981 (\N{CJK UNIFIED IDEOGRAPH-4E0D}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 21516 (\N{CJK UNIFIED IDEOGRAPH-540C}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 30340 (\N{CJK UNIFIED IDEOGRAPH-7684}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 39044 (\N{CJK UNIFIED IDEOGRAPH-9884}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 27979 (\N{CJK UNIFIED IDEOGRAPH-6D4B}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 27491 (\N{CJK UNIFIED IDEOGRAPH-6B63}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 30830 (\N{CJK UNIFIED IDEOGRAPH-786E}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 24635 (\N{CJK UNIFIED IDEOGRAPH-603B}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 20307 (\N{CJK UNIFIED IDEOGRAPH-4F53}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 20934 (\N{CJK UNIFIED IDEOGRAPH-51C6}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 26679 (\N{CJK UNIFIED IDEOGRAPH-6837}) missing from font(s) Arial.
C:\python\py\3.py:186: UserWarning:
Glyph 26412 (\N{CJK UNIFIED IDEOGRAPH-672C}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 26041 (\N{CJK UNIFIED IDEOGRAPH-65B9}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 24046 (\N{CJK UNIFIED IDEOGRAPH-5DEE}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 21306 (\N{CJK UNIFIED IDEOGRAPH-533A}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 38388 (\N{CJK UNIFIED IDEOGRAPH-95F4}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 19981 (\N{CJK UNIFIED IDEOGRAPH-4E0D}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 21516 (\N{CJK UNIFIED IDEOGRAPH-540C}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 30340 (\N{CJK UNIFIED IDEOGRAPH-7684}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 39044 (\N{CJK UNIFIED IDEOGRAPH-9884}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 27979 (\N{CJK UNIFIED IDEOGRAPH-6D4B}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 27491 (\N{CJK UNIFIED IDEOGRAPH-6B63}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 30830 (\N{CJK UNIFIED IDEOGRAPH-786E}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 24635 (\N{CJK UNIFIED IDEOGRAPH-603B}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 20307 (\N{CJK UNIFIED IDEOGRAPH-4F53}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 20934 (\N{CJK UNIFIED IDEOGRAPH-51C6}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 26679 (\N{CJK UNIFIED IDEOGRAPH-6837}) missing from font(s) Arial.
C:\python\PyCharm 2024.3.5\plugins\python-ce\helpers\pycharm_matplotlib_backend\backend_interagg.py:124: UserWarning:
Glyph 26412 (\N{CJK UNIFIED IDEOGRAPH-672C}) missing from font(s) Arial.
choreographer.browsers.chromium.ChromeNotFoundError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\python\py\.venv\Lib\site-packages\plotly\io\_kaleido.py", line 380, in to_image
img_bytes = kaleido.calc_fig_sync(
fig_dict,
...<7 lines>...
kopts=kopts,
)
File "C:\python\py\.venv\Lib\site-packages\kaleido\__init__.py", line 145, in calc_fig_sync
return _async_thread_run(calc_fig, args=args, kwargs=kwargs)
File "C:\python\py\.venv\Lib\site-packages\kaleido\__init__.py", line 138, in _async_thread_run
raise res
File "C:\python\py\.venv\Lib\site-packages\kaleido\__init__.py", line 129, in run
q.put(asyncio.run(func(*args, **kwargs)))
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Ran\AppData\Local\Programs\Python\Python313\Lib\asyncio\runners.py", line 195, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "C:\Users\Ran\AppData\Local\Programs\Python\Python313\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "C:\Users\Ran\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py", line 725, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "C:\python\py\.venv\Lib\site-packages\kaleido\__init__.py", line 54, in calc_fig
async with Kaleido(**kopts) as k:
~~~~~~~^^^^^^^^^
File "C:\python\py\.venv\Lib\site-packages\kaleido\kaleido.py", line 128, in __init__
raise ChromeNotFoundError(
...<4 lines>...
) from ChromeNotFoundError
choreographer.browsers.chromium.ChromeNotFoundError: Kaleido v1 and later requires Chrome to be installed. To install Chrome, use the CLI command `kaleido_get_chrome`, or from Python, use either `kaleido.get_chrome()` or `kaleido.get_chrome_sync()`.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\python\py\3.py", line 356, in <module>
save_all_figures()
~~~~~~~~~~~~~~~~^^
File "C:\python\py\3.py", line 270, in save_all_figures
fig.write_image('4_box_trend.png', scale=3)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\python\py\.venv\Lib\site-packages\plotly\basedatatypes.py", line 3895, in write_image
return pio.write_image(self, *args, **kwargs)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "C:\python\py\.venv\Lib\site-packages\plotly\io\_kaleido.py", line 510, in write_image
img_data = to_image(
fig,
...<5 lines>...
engine=engine,
)
File "C:\python\py\.venv\Lib\site-packages\plotly\io\_kaleido.py", line 392, in to_image
raise RuntimeError(PLOTLY_GET_CHROME_ERROR_MSG)
RuntimeError:
Kaleido requires Google Chrome to be installed.
Either download and install Chrome yourself following Google's instructions for your operating system,
or install it from your terminal by running:
$ plotly_get_chrome
进程已结束,退出代码为 1