python调用Matplotlib绘制分布点图

yipeiwu_com5年前Python基础

Python调用Matplotlib代码绘制分布点,供大家参考,具体内容如下

  • 绘制点图的目的
  • Matplotlib简介
  • 代码
  • 截图

1.绘制点图的目的

我们实验室正在做关于人脸识别的项目,其中在人脸检测后,会有些误检的图片,但是其中就有很多不符合的。很明显的是从图片大小,就可以过滤掉一部分。老大交给我的工作,就是通过绘制图片width,height的分布图,来找到一个合理的阈值。

2.Matlablib简介

Matplotlib是一个Python的图形框架

下面是官网的例子

Matplotlib example

3.代码如下

import matplotlib.pyplot as plt
from numpy.random import rand
import numpy
import os
import cv2

#setting plt
plt.xlim(xmax=500,xmin=0)
plt.ylim(ymax=500,ymin=0)
plt.xlabel("height")
plt.ylabel("width")


path_1 = r'D:\zhangjichao\view\path_1'


x = []
y = []
files = os.listdir(path_1)
for f in files:
  img = cv2.imread(path_1 + '\\' + f)
  x.append(img.shape[0])
  y.append(img.shape[1])
plt.plot(x,y,'ro',color='red',label='path_1')

path_2 = r'D:\zhangjichao\view\path_2'

x = []
y = []
files = os.listdir(path_2)
for f in files:
  img = cv2.imread(path_2 + '\\' + f)
  x.append(img.shape[0])
  y.append(img.shape[1])
plt.plot(x,y,'ro',color='red',label='path_2')

path_3 = r'D:\zhangjichao\view\path_3'


x = []
y = []
files = os.listdir(path_3)
for f in files:
  img = cv2.imread(path_3 + '\\' + f)
  x.append(img.shape[0])
  y.append(img.shape[1])
plt.plot(x,y,'ro',color='red',label='path_3')

path_4 = r'D:\zhangjichao\view\path_4'

x = []
y = []
files = os.listdir(path_4)
for f in files:
  img = cv2.imread(path_4 + '\\' + f)
  x.append(img.shape[0])
  y.append(img.shape[1])
plt.plot(x,y,'ro',color='red',label='path_4')

yujing = r'D:\zhangjichao\view\xujing'

x = []
y = []
files = os.listdir(yujing)
for f in files:
  img = cv2.imread(yujing + '\\' + f)
  x.append(img.shape[0])
  y.append(img.shape[1])
plt.plot(x,y,'ro',color='green' , label='yujing')

#图例
plt.legend(loc='upper center', shadow=True, fontsize='x-large')
plt.grid(True)

#显示
plt.show()

4.显示结果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

pycharm修改界面主题颜色的方法

pycharm修改界面主题颜色的方法

如下所示: 以上这篇pycharm修改界面主题颜色的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。...

用Python的pandas框架操作Excel文件中的数据教程

用Python的pandas框架操作Excel文件中的数据教程

引言 本文的目的,是向您展示如何使用pandas 来执行一些常见的Excel任务。有些例子比较琐碎,但我觉得展示这些简单的东西与那些你可以在其他地方找到的复杂功能同等重要。作为额外的福利...

Python入门之三角函数atan2()函数详解

描述 atan2() 返回给定的 X 及 Y 坐标值的反正切值。 语法 以下是 atan2() 方法的语法: import math math.atan2(y, x) 注意:...

写了个监控nginx进程的Python脚本

复制代码 代码如下: #!/usr/bin/env python import os, sys, time while True: time.sleep(3) try: ret = os...

Python实现Mysql数据库连接池实例详解

Python实现Mysql数据库连接池实例详解

python连接Mysql数据库: Python编程中可以使用MySQLdb进行数据库的连接及诸如查询/插入/更新等操作,但是每次连接MySQL数据库请求时,都是独立的去请求访问,相当...