import matplotlib.pyplot as plt
import io
# 图像设置
fig, ax = metric.plot()
......
# 设置好后,保存并显示
fig.savefig("./ConfusionMatrix.png")
plt.show()
# 将绘制的图像以base64格式传递到前端
save_file = io.BytesIO()
fig.savefig(save_file, format='png')
# 转换base64并以utf8格式输出
save_file_base64 = base64.b64encode(save_file.getvalue()).decode('utf8')
matplotlib.pyplot将绘制的图像以base64格式传递到前端
于 2024-05-29 17:43:02 首次发布