python調(diào)用Matplotlib繪制分布點(diǎn)并且添加標(biāo)簽
本文實(shí)例為大家分享了Python調(diào)用Matplotlib繪制分布點(diǎn)添加標(biāo)簽的具體代碼,供大家參考,具體內(nèi)容如下
- 添加標(biāo)簽的目的
- 代碼
- 截圖
目的
上文介紹了根據(jù)圖像的大小作為坐標(biāo)來(lái)繪制分布點(diǎn)圖。老大又給了我一個(gè)任務(wù),我繪制完,每次將圖保存,發(fā)給她,但是圖片中的點(diǎn)的坐標(biāo)是不能顯示了,所以她讓我給每個(gè)點(diǎn)添加個(gè)label,而且label是該點(diǎn)的橫縱坐標(biāo)。
代碼
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()
截圖

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
pyecharts如何實(shí)現(xiàn)顯示數(shù)據(jù)為百分比的柱狀圖
這篇文章主要介紹了pyecharts如何實(shí)現(xiàn)顯示數(shù)據(jù)為百分比的柱狀圖,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11
python實(shí)現(xiàn)DES加密解密方法實(shí)例詳解
這篇文章主要介紹了python實(shí)現(xiàn)DES加密解密方法,以實(shí)例形式較為詳細(xì)的分析了基于Python實(shí)現(xiàn)的DES加密與解密技巧,需要的朋友可以參考下2015-06-06
Python語(yǔ)言編寫(xiě)智力問(wèn)答小游戲功能
這篇文章主要介紹了使用Python代碼語(yǔ)言簡(jiǎn)單編寫(xiě)一個(gè)輕松益智的小游戲,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
Python通過(guò)socketserver處理多個(gè)鏈接
這篇文章主要介紹了Python通過(guò)socketserver處理多個(gè)鏈接,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
Python3.5內(nèi)置模塊之time與datetime模塊用法實(shí)例分析
這篇文章主要介紹了Python3.5內(nèi)置模塊之time與datetime模塊用法,結(jié)合實(shí)例形式分析了Python3.5 time與datetime模塊日期時(shí)間相關(guān)操作技巧,需要的朋友可以參考下2019-04-04
關(guān)于torch中tensor數(shù)據(jù)類(lèi)型的轉(zhuǎn)換
這篇文章主要介紹了關(guān)于torch中tensor數(shù)據(jù)類(lèi)型的轉(zhuǎn)換方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11
Pygame Surface創(chuàng)建圖像的實(shí)現(xiàn)
本文主要介紹了Pygame Surface創(chuàng)建圖像的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02

