Python 使用mathplotlib显示存储在数组中的图像的坐标

Python 使用mathplotlib显示存储在数组中的图像的坐标,python,matplotlib,Python,Matplotlib,我试着使用mpls游标。但鼠标悬停时,绘图上不会显示任何内容。箭头未显示任何坐标。 我试着在没有图像的情况下绘制点,但仍然没有显示任何坐标 [106 190][205 167]249 280][80 301][343 294][207 151][293 300][30 298][116 301][290 261][38][295 316][209 262][210 285][205 323][282 244][128 158][255 26][133 708][213 243 214 69 6

我试着使用mpls游标。但鼠标悬停时,绘图上不会显示任何内容。箭头未显示任何坐标。 我试着在没有图像的情况下绘制点,但仍然没有显示任何坐标

[106 190][205 167]249 280][80 301][343 294][207 151][293 300][30 298][116 301][290 261][38][295 316][209 262][210 285][205 323][282 244][128 158][255 26][133 708][213 243 214 69 62 241][68 181 254 692][35 21][74 318][290 275 284 178 185 21][207 107][25 323 331 88][113 273][157 293][112 241] [164 323] [250 301] [137 20] [ 35 645] [284 484] [244 317] [ 27 26 9] [356 331] [356 25] [131 279] [206 296] [ 35 490] [139 85] [215 396] [116 150] [139 644] [338 305] [183 330] [140 488] [327 331] [357 550] [187 707] [260 705] [180 646] [282 552] [ 61 554] [113 485] [163 269] [114 642] [287 645] [281 287] [140 241] [327 181] [ 36 552] [242 263] [257 87] [ 52 18] [358 61] [110 397] [359 692] [139 176] [212 23] [140 332] [271 704] [254 359] [ 63 19] [ 37 396] [110 20] [ 65 82] [ 36 176] [211 706] [108 162] [ 65 397] [212 552] [ 62 645] [109 550] [256 240] [283 24] [185 552] [286 86] [186 242] [355 180] [141 550] [ 64 707] [283 704] [285 330] [257 398] [185 398] [285 398] [109 126] [356 89] [ 37 709] [ 64 331] [111 316] [ 35 334] [214 487][328 241][119 172][212 88][356 244][253 332][39 240][328 27][359 395][77 266][358 641][211 642][110 706][181 151][140 396][110 332][64 489][182 486][328 396][254 485][195 256 549][111 83][328 639][253 179 339 270][206 135][325 488]这是coords阵列。 那个么,如何根据图像的形状将坐标保存在一个变量中呢?只有第一行中的矩形。 我的图像是一系列矩形传感器。这就是为什么我尝试通过鼠标单击来查找坐标。

自动创建带有x和y位置的注释。只有在需要额外信息时,才需要编写函数来根据所选点更改注释

下面是一些代码,使用随机图像显示其工作原理:

导入matplotlib.pyplot作为plt
将numpy作为np导入
导入MPLS游标
coords=np.数组([301557]、[301378]、[201426]、[77,58]、[243,12]、[466,87]、[161,75]、[302489]、[197507]、[157400]、[131,85]、[379253]、[386525]、[215500]、[165963]、[210381]、[308254]、[285378]、[217628]、[77500]、[156629]、[527,67]、[5141010]、[234264]、[523717]、[282630]、[523737373799]、[3535357]、[3775]、[23757]、[3575]、[23757]、[3575]、[3575]、[2375],[451,409],[130,247],[384,509],[309,473],[202,937],[130,561],[340,549],[310,627],[348,256],[381,869],[258,555],[342,417],[204,393],[385,489],[523,483],[303,784],[448,476],[228,939],[229,559],[454,260],[158,939],[109,521],[158,248],[160,561],[425,319],[129,939],[526,263],[221,389],[236,754],[203,628],[335,492],[453,319],[160,313],[197,76],[420,410],[129,874],[279,250],[130,310],[206,472],[352,1017],[228,508],[117,555],[278,783],[306,937],[424,475],[157,874],[235,407],[78,552],[129,625],[128,781],[423,934],[349,316],[202,781],[378,935],[475,543],[204,547],[391,546],[424,253],[202,251],[170,549],[236,781],[132,471],[75,959],[128,407],[200,356],[309,716],[232,715],[422,629],[274,562],[201,563],[234,471],[149,89],[277,713],[290,12],[236,313],[161,720],[383,626],[350,867],[451,782],[379,783],[450,934],[166,467],[347,626],[450,559],[451,712],[418,875],[379,318],[156,1018],[306,871],[379,408],[278,471],[203,715],[161,782],[203,872],[277,936],[234,874],[348,933],[235,627],[420,561],[438,502],[204,314],[263,499],[279,317],[421,780],[453,627],[334,959],[174,496],[125,500],[131,542],[159,545],[352,499],[79,1012],[417,501],[501,128],[295,340],[215,543],[218,358],[168,1020],[112,504],[158,502]])
图,ax=plt.子批次()
img=np.rand.rand(5501050)
ax.imshow(img,cmap='gray')
绘图点=最大绘图点(坐标[:,1],坐标[:,0],颜色为青色,标记为o,线型为无,标记为2)
mplcursors.cursor(标绘点,悬停=True)
plt.show()

从matplotlib导入pyplot作为plt导入numpy作为np导入skimage.color导入skimage.filters from skimage.feature导入corner_harris,corner_subpix,corner_Peaks输入图像是传感器的镜像,它们是矩形。在绘图中,角点被绘制出来。但坐标没有显示。我需要显示传感器的角点矩形。请在帖子中添加缺少的导入和额外信息。您是否查看了
plt.text()
以将坐标作为文本写入绘图?坐标数组非常大(174,2),如何执行此操作。?您希望结果看起来如何?您尝试了什么?如果永久显示坐标会导致绘图过于繁忙,则可以在鼠标悬停时仅显示坐标,但仍显示任何坐标。我已在上面添加了编辑代码和尖叫声。%matplotlib notebook,我添加了此行及其工作方式ng,thanksI我正在使用Juypternotebook。使用标准的内联matplotlib,绘图就像Jupyter中的静止图像,没有缩放,也没有在悬停时显示坐标。我怀疑,为什么使用鼠标显示的坐标与Coords数组中的值不同。?
    from nptdms import TdmsFile as td  
    from matplotlib import pyplot as plt
    import numpy as np
    import skimage.color
    import skimage.filters
    import mplcursors
    from skimage.feature import corner_harris,corner_peaks
    
    file = 'sample.tdms' 
    with td.open(file) as tdms_file:
     img = tdms_file.as_dataframe()
    cropped_list = []
    sel=cropped_list.append(img.iloc[700:1250,450:1550:])
coords=corner_peaks(corner_harris(sel),min_distance=10,threshold_rel=0.02)
    fig, ax = plt.subplots()
    ax.imshow(sel, cmap='gray')
    plotted_points =ax.plot(coords[:, 1], coords[:, 0], color='cyan', marker='o',linestyle='None', markersize=2) 
    mplcursors.cursor(plotted_points, hover=True)
    plt.show(