赞
踩
import matplotlib.pyplot as plt import matplotlib.ticker as ticker xx = [] yy = [] th = [] def OutputCoordinate(x,y,th): strlist="x=%.2f,y=%.2f,th=%.2f"%(x,y,th) # PointTipText=plt.text(x,y*1.02,strlist, ha='center', va='bottom', fontsize=10) # plt.text(x,y*1.02,str('/'), ha='center', va='bottom', fontsize=10.5) # plt.text(x+0.07,y*1.02,"y=%.2f"%y, ha='center', va='bottom', fontsize=10) # print(x,y) # print(PointTipText) return strlist def mapdataDispose(): Path = "D:\RTK_DATA_DISPOSE\RTKtest\\mapdata.txt" infile = open(Path, 'rb') numCount=0 line=infile.readline() while line: a=line.split() x=float(a[0]) y=float(a[1]) angle=float(a[2]) # if numCount%2==0: xx.append(x) yy.append(y) th.append(angle) OutputCoordinate(x,y,angle) numCount=numCount+1 line=infile.readline() # point,=plt.plot(xx,yy,marker = "+",markersize=7)#marker设置标记形状 markersize设置标记大小 # plt.xlim(1,100)#限制取值范围 # plt.ylim(1,100) # plt.xticks(np.arange(-10,10,1))#设置取值范围和间隔 # plt.yticks(np.arange(-10,10,1)) # plt.legend() # 显示图例 # plt.grid() # 生成网格 # plt.show() infile.close() def RelocationdataDispose(): Path = "D:\RTK_DATA_DISPOSE\RTKtest\\relocation.txt" infile = open(Path, 'rb') numCount=0 line=infile.readline() while line: a=line.split() # plt.plot(gpsData[numCount,1],gpsData[numCount,2],'ro') x=float(a[1]) y=float(a[2]) angle=float(a[0]) # if numCount%2==0: xx.append(x) yy.append(y) th.append(angle) OutputCoordinate(x,y,angle) numCount=numCount+1 line=infile.readline() # point,=plt.plot(xx,yy,marker = "+",markersize=7)#marker设置标记形状 markersize设置标记大小 # plt.xlim(1,100)#限制取值范围 # plt.ylim(1,100) # plt.xticks(np.arange(-10,10,1))#设置取值范围和间隔 # plt.yticks(np.arange(-10,10,1)) # plt.legend() # 显示图例 # plt.grid() # 生成网格 # plt.show() infile.close() def ODOdataDispose(): Path = "D:\RTK_DATA_DISPOSE\RTKtest\\mapdata.txt" infile = open(Path, 'rb') numCount=0 line=infile.readline() while line: a=line.split() # plt.plot(gpsData[numCount,1],gpsData[numCount,2],'ro') x=float(a[2]) y=float(a[3]) angle=float(a[5]) # if numCount%2==0: xx.append(x) yy.append(y) th.append(angle) OutputCoordinate(x,y,angle) numCount=numCount+1 line=infile.readline() # point,=plt.plot(xx,yy,marker = "+",markersize=7)#marker设置标记形状 markersize设置标记大小 # plt.xlim(1,100)#限制取值范围 # plt.ylim(1,100) # plt.xticks(np.arange(-10,10,1))#设置取值范围和间隔 # plt.yticks(np.arange(-10,10,1)) # plt.legend() # 显示图例 # plt.grid() # 生成网格 # plt.show() infile.close() # 定义鼠标响应函数 def on_move(event): visibility_changed = False for point, annotation in po_annotation1: should_be_visible = (point.contains(event)[0] == True) if should_be_visible != annotation.get_visible(): visibility_changed = True annotation.set_visible(should_be_visible) if visibility_changed: # fig.canvas.draw_idle()#重新绘制整个图表 plt.plot(xx,yy,'b',marker = "+",markersize=7)#marker设置标记形状 markersize设置标记大小 plt.draw() mapdataDispose(); #RelocationdataDispose(); # ODOdataDispose() fig,ax = plt.subplots() # fig.set_size_inches(24, 12) # po_annotation1 为 ‘买’ 时需要显示的标注信息 # 该 list 内部存放多个子 list,每个子 list 为 [标注点的坐标, 标注] po_annotation1 = [] for i in range(len(xx)): # 标注点的坐标 point_x = xx[i] point_y = yy[i] point_th = th[i] point, = plt.plot(point_x, point_y,'b.:',markersize=7,linewidth=1) # print(point) # 标注框偏移量 offset1 = 20 offset2 = 20 # 标注框 bbox1 = dict(boxstyle="round", fc='lightgreen', alpha=0.6) # 标注箭头 arrowprops1 = dict(arrowstyle="->", connectionstyle="arc3,rad=0.") # 标注 annotation = plt.annotate((i,OutputCoordinate(point_x,point_y,point_th)), xy=(point_x,point_y), xytext=(-offset1, offset2), textcoords='offset points', bbox=bbox1, arrowprops=arrowprops1, size=15) # 默认鼠标未指向时不显示标注信息 annotation.set_visible(False) po_annotation1.append([point, annotation]) # 鼠标移动事件 on_move_id = fig.canvas.mpl_connect('motion_notify_event', on_move) plt.legend() # 显示图例 plt.grid() # 生成网格 plt.show()
用python画地图数据,并输出图形
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。