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中open()函数指定文件打开方式的用法

文件打开方式 当我们用open()函数去打开文件的时候,有好几种打开的模式。 'r'->只读 'w'->只写,文件已存在则清空,不存在则创建。 'a'->追加,写到文件...

浅谈Django+Gunicorn+Nginx部署之路

前言 最近,我已经成功将我的个人网站从 Flask 迁移到 Django 了,最早接触 Django 的时候大概是在 4 年前,我记得那个时候 Django 中的路由配置使用 正则 来...

对django 模型 unique together的示例讲解

unique_together 这个元数据是非常重要的一个!它等同于数据库的联合约束! 举个例子,假设有一张用户表,保存有用户的姓名、出生日期、性别和籍贯等等信息。要求是所有的用户唯一不...

Python常见的pandas用法demo示例

本文实例总结了Python常见的pandas用法。分享给大家供大家参考,具体如下: import numpy as np import pandas as pd s = p...

python 两个数据库postgresql对比

这篇文章主要介绍了python 两个数据库postgresql对比,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 比较两个postgr...