当前位置:   article > 正文

PYTHON画地图_python 地图 annotation

python 地图 annotation
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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160

用python画地图数据,并输出图形

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/725591
推荐阅读
相关标签
  

闽ICP备14008679号