def plot_cpu_mem_keypoints(self):
        """绘制CPU/Mem/特征点数量."""
        plt.figure(1)
        # 开始绘制子图:
        plt.subplot(311)
        title = self._get_graph_title()
        plt.title(title, loc="center")  # 设置绘图的标题
        mem_ins = plt.plot(self.time_axis, self.mem_axis, "-", label="Mem(MB)", color='deepskyblue', linestyle='-', marker=',')
        # 设置数字标签
        plt.legend(mem_ins, ["Mem(MB)"], loc='upper right')  # 说明标签的位置
        plt.grid()  # 加网格
        plt.ylabel("Mem(MB)")
        plt.ylim(bottom=0)
        for method_exec in self.method_exec_info:
            start_date = datetime.fromtimestamp(method_exec["start_time"])
            end_date = datetime.fromtimestamp(method_exec["end_time"])
            plt.vlines(start_date, 0, self.max_mem, colors="c", linestyles="dashed")  # vlines(x, ymin, ymax)
            plt.vlines(end_date, 0, self.max_mem, colors="c", linestyles="dashed")  # vlines(x, ymin, ymax)
            # 绘制mem文字:
            x = datetime.fromtimestamp(method_exec["mem_max_time"])
            text = "%s: %d MB" % (method_exec["name"], method_exec["mem_max"])
            plt.text(x, method_exec["mem_max"], text, ha="center", va="bottom", fontsize=10)
            plt.plot(x, method_exec["mem_max"], 'bo', label="point")  # 绘制点

        # 绘制子图2
        plt.subplot(312)
        cpu_ins = plt.plot(self.time_axis, self.cpu_axis, "-", label="CPU(%)", color='red', linestyle='-', marker=',')
        plt.legend(cpu_ins, ["CPU(%)"], loc='upper right')  # 说明标签的位置
        plt.grid()  # 加网格
        plt.xlabel("Time(s)")
        plt.ylabel("CPU(%)")
        plt.ylim(0, 120)
        for method_exec in self.method_exec_info:
            start_date = datetime.fromtimestamp(method_exec["start_time"])
            end_date = datetime.fromtimestamp(method_exec["end_time"])
            plt.vlines(start_date, 0, 100, colors="c", linestyles="dashed")  # vlines(x, ymin, ymax)
            plt.vlines(end_date, 0, 100, colors="c", linestyles="dashed")  # vlines(x, ymin, ymax)
            # 绘制mem文字:
            x = datetime.fromtimestamp(method_exec["cpu_max_time"])
            text = "%s: %d%%" % (method_exec["name"], method_exec["cpu_max"])
            plt.text(x, method_exec["cpu_max"], text, ha="center", va="bottom", fontsize=10)
            plt.plot(x, method_exec["cpu_max"], 'ro', label="point")  # 绘制点

        # 绘制子图3
        plt.subplot(313)  # 绘制一下柱状图(关键点)
        # 设置轴向标签
        plt.xlabel('methods')
        plt.ylabel('keypoints number')
        method_list, method_pts_length_list, color_list = [], [], []
        for method_exec in self.method_exec_info:
            for item in ["kp_sch", "kp_src", "good"]:
                method_list.append("%s-%s" % (method_exec["name"], item))
                method_pts_length_list.append(method_exec[item])
                if method_exec["result"]:
                    color_list.append(["palegreen", "limegreen", "deepskyblue"][["kp_sch", "kp_src", "good"].index(item)])
                else:
                    color_list.append("tomato")
        method_x = np.arange(len(method_list)) + 1
        plt.bar(method_x, method_pts_length_list, width=0.35, align='center', color=color_list, alpha=0.8)
        plt.xticks(method_x, method_list, size='small', rotation=30)
        # 设置数字标签
        for x, y in zip(method_x, method_pts_length_list):
            plt.text(x, y + 10, "%d" % y, ha="center", va="bottom", fontsize=7)
        plt.ylim(0, max(method_pts_length_list) * 1.2)

        # 显示图像
        plt.show()
def plot_cpu_mem_keypoints ( self ) : plt . figure ( 1 ) plt . subplot ( 311 ) title = self . _get_graph_title ( ) plt . title ( title , loc = "center" ) mem_ins = plt . plot ( self . time_axis , self . mem_axis , "-" , label = "Mem(MB)" , color = 'deepskyblue' , linestyle = '-' , marker = ',' ) plt . legend ( mem_ins , [ "Mem(MB)" ] , loc = 'upper right' ) plt . grid ( ) plt . ylabel ( "Mem(MB)" ) plt . ylim ( bottom = 0 ) for method_exec in self . method_exec_info : start_date = datetime . fromtimestamp ( method_exec [ "start_time" ] ) end_date = datetime . fromtimestamp ( method_exec [ "end_time" ] ) plt . vlines ( start_date , 0 , self . max_mem , colors = "c" , linestyles = "dashed" ) plt . vlines ( end_date , 0 , self . max_mem , colors = "c" , linestyles = "dashed" ) x = datetime . fromtimestamp ( method_exec [ "mem_max_time" ] ) text = "%s: %d MB" % ( method_exec [ "name" ] , method_exec [ "mem_max" ] ) plt . text ( x , method_exec [ "mem_max" ] , text , ha = "center" , va = "bottom" , fontsize = 10 ) plt . plot ( x , method_exec [ "mem_max" ] , 'bo' , label = "point" ) plt . subplot ( 312 ) cpu_ins = plt . plot ( self . time_axis , self . cpu_axis , "-" , label = "CPU(%)" , color = 'red' , linestyle = '-' , marker = ',' ) plt . legend ( cpu_ins , [ "CPU(%)" ] , loc = 'upper right' ) plt . grid ( ) plt . xlabel ( "Time(s)" ) plt . ylabel ( "CPU(%)" ) plt . ylim ( 0 , 120 ) for method_exec in self . method_exec_info : start_date = datetime . fromtimestamp ( method_exec [ "start_time" ] ) end_date = datetime . fromtimestamp ( method_exec [ "end_time" ] ) plt . vlines ( start_date , 0 , 100 , colors = "c" , linestyles = "dashed" ) plt . vlines ( end_date , 0 , 100 , colors = "c" , linestyles = "dashed" ) x = datetime . fromtimestamp ( method_exec [ "cpu_max_time" ] ) text = "%s: %d%%" % ( method_exec [ "name" ] , method_exec [ "cpu_max" ] ) plt . text ( x , method_exec [ "cpu_max" ] , text , ha = "center" , va = "bottom" , fontsize = 10 ) plt . plot ( x , method_exec [ "cpu_max" ] , 'ro' , label = "point" ) plt . subplot ( 313 ) plt . xlabel ( 'methods' ) plt . ylabel ( 'keypoints number' ) method_list , method_pts_length_list , color_list = [ ] , [ ] , [ ] for method_exec in self . method_exec_info : for item in [ "kp_sch" , "kp_src" , "good" ] : method_list . append ( "%s-%s" % ( method_exec [ "name" ] , item ) ) method_pts_length_list . append ( method_exec [ item ] ) if method_exec [ "result" ] : color_list . append ( [ "palegreen" , "limegreen" , "deepskyblue" ] [ [ "kp_sch" , "kp_src" , "good" ] . index ( item ) ] ) else : color_list . append ( "tomato" ) method_x = np . arange ( len ( method_list ) ) + 1 plt . bar ( method_x , method_pts_length_list , width = 0.35 , align = 'center' , color = color_list , alpha = 0.8 ) plt . xticks ( method_x , method_list , size = 'small' , rotation = 30 ) for x , y in zip ( method_x , method_pts_length_list ) : plt . text ( x , y + 10 , "%d" % y , ha = "center" , va = "bottom" , fontsize = 7 ) plt . ylim ( 0 , max ( method_pts_length_list ) * 1.2 ) plt . show ( )
绘制CPU/Mem/特征点数量.