python调用Matplotlib绘制分布点并且添加标签

yipeiwu_com5年前Python基础

本文实例为大家分享了Python调用Matplotlib绘制分布点添加标签的具体代码,供大家参考,具体内容如下

  • 添加标签的目的
  • 代码
  • 截图

目的

上文介绍了根据图像的大小作为坐标来绘制分布点图。老大又给了我一个任务,我绘制完,每次将图保存,发给她,但是图片中的点的坐标是不能显示了,所以她让我给每个点添加个label,而且label是该点的横纵坐标。

代码

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

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


path_1 = r'D:\zhangjichao\view\V7_scale_2\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\V7_scale_2\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\V7_scale_2\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\V7_scale_2\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\V7_scale_2\xujing_org_scale_2'

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='xujing')
for i in range(1,len(x)):
  plt.text(x[i],y[i],str((x[i],y[i])), family='serif', style='italic', ha='right', wrap=True)

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


plt.show()

截图

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

相关文章

python实现Virginia无密钥解密

本文实例为大家分享了Virginia无密钥解密的具体代码,供大家参考,具体内容如下 加密 virginia加密是一种多表替换加密方法,通过这种方法,可以有效的解决单表替换中无法应对的字...

Python将列表中的元素转化为数字并排序的示例

本文实例讲述了Python中列表元素转为数字的方法。分享给大家供大家参考,具体如下: 有一个数字字符的列表: numbers = ['2', '4', '1', '3'] 想要把每...

Python实现的密码强度检测器示例

本文实例讲述了Python实现的密码强度检测器。分享给大家供大家参考,具体如下: 密码强度 密码强度如何量化呢? 一个密码可以有以下几种类型:长度、大写字母、小写字母、数字以及特殊符号。...

Python函数定义及传参方式详解(4种)

一、函数初识 1、定义:将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数名即可。  2、好处:代码重用;保持一致性;可扩展性。 3、示例如下:    ...

Python全局变量用法实例分析

本文实例讲述了Python全局变量用法。分享给大家供大家参考,具体如下: 全局变量不符合参数传递的精神,所以,平时我很少使用,除非定义常量。今天有同事问一个关于全局变量的问题,才发现其中...