matplotlib:绘制简单图像

以绘制PR曲线为例

  • 绘制10张PR曲线
  • p_list和r_list分别为每张PR曲线的precision点和recall点
  • 动态显示,每隔1秒绘制下一张图

源码:

# 循环绘制10类PR曲线
def all_pr_curve(dict_path="res/"):
    for i in range(1,11):
        p_list, r_list = get_precision_recall_list(class_id=i, dict_path=dict_path)
        plt.figure(i)  # 创建图表
        plt.ion()      # 交互模式开启,使figure自动刷新显示
        plt.title('PR Curve for class ' + str(i))
        plt.xlabel('Recall')        # 坐标轴label
        plt.ylabel('Precision')     # 坐标轴label
        plt.xlim(xmin=0, xmax=1)    # 坐标轴范围
        plt.ylim(ymin=0, ymax=1)    # 坐标轴范围
        plt.plot(r_list, p_list, color="r", linestyle="--", marker="*", linewidth=1.0) # 绘制!
        plt.pause(1)    # 暂停1秒
        plt.ioff()      # 交互模式关闭
        # plt.show()

效果:
在这里插入图片描述

发布了52 篇原创文章 · 获赞 4 · 访问量 2142

猜你喜欢

转载自blog.csdn.net/qq_42191914/article/details/103826546