from matplotlib import pyplot as plt
# 参数依次为list,抬头,X轴标签,Y轴标签,XY轴的范围
def draw_hist(myList, Title, Xlabel, Ylabel, Xmin, Xmax, Ymin, Ymax):
plt.hist(myList, 50) # bins = 50,顺便可以控制bin宽度
plt.xlim(Xmin, Xmax)
plt.ylim(Ymin, Ymax)
plt.xlabel(Xlabel) # 横轴名
plt.ylabel(Ylabel) # 纵轴名
plt.title(Title)
plt.show()
draw_hist(area_list, 'Area Statistics of Different Images', 'Area', 'number', 0, 6000, 0.0, 3) # 直方图展示
--------------------------------------------------------------------------------------------------------------------------------------------
画 list[list]数据类型的hist
# 统计预测结果图像中所有mask面积
def area_statistics(pred):
pred_conts = get_cnts(pred)
area_list = []
for c_num in range(len(pred_conts)):
area = cv2.contourArea(pred_conts[c_num])
area_list.append(area)
return area_list
area_list = self.area_statistics(pred_img)
all_img_area_list.append(area_list)
self.draw_hist(all_img_area_list, 'Area Statistics of Different Images', 'Area', 'number', 0, 6000, 0.0, 3) # 直方图展示
效果如下:
同一张图像上的不同区域的面积,用相同的颜色表示。