需解决问题:
1.离散点进行平滑曲线画法
https://blog.csdn.net/cdqn10086/article/details/70143616
def draw_curve(x,y,img_save_dir,auc): xnew = np.linspace(x.min(),x.max(),300) y_smooth = spline(x,y,xnew) plt.plot(xnew,y_smooth) plt.savefig(img_save_dir)
2.把auc计算的结果画到图片上,使用plt.text,即文本显示
官网给的方法:https://matplotlib.org/users/text_intro.html
def draw_curve(x,y,img_save_dir,auc): xnew = np.linspace(x.min(),x.max(),300) y_smooth = spline(x,y,xnew) fig = plt.figure() ax = fig.add_subplot(111) ax.text(100,100,r'%f'%auc,fontsize=160) ax.plot(xnew,y_smooth) plt.savefig(img_save_dir)
也可以这样使用:
def draw_curve(x,y,img_save_dir,auc): xnew = np.linspace(x.min(),x.max(),300) y_smooth = spline(x,y,xnew) plt.plot(xnew,y_smooth) plt.text(20,0.5,r'%f'%auc,fontsize=16) plt.savefig(img_save_dir)
注意:1.以上无论是哪种方法都可以,但要注意text的第一个坐标是x,第二个是y,也就是你把这个文字放在你画的坐标轴的什么位置,比如我的坐标轴是x轴0-50,y轴0-1,但我写了个plt.text(100,100),运行代码不会报错,但就是一直没有结果进行显示在图片上.
2.记得python的格式化输出%
auc的计算现在是直接按照中间值进行计算,但我感觉还是有点不太对