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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python連接MySQL數(shù)據(jù)庫的簡單便捷方法
在數(shù)據(jù)分析過程中往往要操作較大的數(shù)據(jù)集,這就需要連接數(shù)據(jù)庫進(jìn)行操作,下面這篇文章主要給大家介紹了關(guān)于Python連接MySQL數(shù)據(jù)庫的簡單便捷方法,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04
Python常用類型轉(zhuǎn)換實現(xiàn)代碼實例
這篇文章主要介紹了Python常用類型轉(zhuǎn)換實現(xiàn)代碼實例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-07-07
基于python實現(xiàn)簡單網(wǎng)頁服務(wù)器代碼實例
這篇文章主要介紹了基于python實現(xiàn)簡單網(wǎng)頁服務(wù)器代碼實例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-09-09
解決pycharm上的jupyter notebook端口被占用問題
今天小編就為大家分享一篇解決pycharm上的jupyter notebook端口被占用問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12
Python標(biāo)準(zhǔn)庫calendar的使用方法
本文主要介紹了Python標(biāo)準(zhǔn)庫calendar的使用方法,calendar模塊主要由Calendar類與一些模塊方法構(gòu)成,Calendar類又衍生了一些子孫類來幫助我們實現(xiàn)一些特殊的功能,感興趣的可以了解一下2021-11-11
基于python?win32setpixel?api?實現(xiàn)計算機圖形學(xué)相關(guān)操作(推薦)
這篇文章主要介紹了基于python?win32setpixel?api?實現(xiàn)計算機圖形學(xué)相關(guān)操作,這次的主要分為2個主要模塊,一個是實現(xiàn)畫線,畫圓的算法,還有填充的算法,以及裁剪的算法,需要的朋友可以參考下2021-12-12

