IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> Python画轨迹图 -> 正文阅读

[人工智能]Python画轨迹图

?

import cmath
import re
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import math
from matplotlib.animation import FuncAnimation
import os

azimuth_list = []
distance_list = []

# x_axis = []
# y_axis = []

aoa_loc_data = []

index = 0
curve = 0

output_gif = "output\\gif\\"
output_csv = "output\\csv\\"
output_png = "output\\png\\"
def create_csv(file_input, line, data):
    global azimuth
    global distance

    with open(file_input, 'w') as file_ob:
        while line:
            line = data.readline()

            tmp_distance_re = re.search(r'Distance \d+', line)
            tmp_azimuth_re = re.search(r'AoA azimuth -?\d+', line)
            if tmp_distance_re and tmp_azimuth_re:
                distance = int(tmp_distance_re.group(0).replace('Distance ', ''))
                distance /= 100
                azimuth = int(tmp_azimuth_re.group(0).replace('AoA azimuth ', ''))
                #azimuth = 0
                file_ob.write('%.02f,%d\n' % (distance, azimuth))
                #
                # print('原始:%.02fm %d' % (distance, azimuth))
                # azimuth = 0 - azimuth;
                # print('镜像:%.02fm %d' % (distance, azimuth))
                # #azimuth = azimuth if (azimuth >= 0) else (azimuth + 360)
                # azimuth = azimuth * np.pi / 180.
                # print("弧度:%.02fm %f" % (distance, azimuth))
                # file_ob.write('%.02f,%.02f\n' % (distance, azimuth))



def load_file(file_name):
    _log_file_name = file_name + '.log'
    _csv_filename = os.path.join(output_csv, file_name)
    _csv_filename = _csv_filename + '.csv'
    data = open(_log_file_name)
    line = data.readline()
    create_csv(_csv_filename, line, data)
    data.close()


def load_data(file_name):
    global aoa_loc_data
    #csv_filename = file_name + '.csv'
    _csv_filename = os.path.join(output_csv, file_name)
    _csv_filename = _csv_filename + '.csv'

    load_file(file_name)
    aoa_loc_data = pd.read_csv(_csv_filename, header=None)

    print(len(aoa_loc_data[0]))
    print(len(aoa_loc_data[1]))

def update_graph(step):
    #print(azimuth_list)
    #print(distance_list)
    global index
    global curve
    #print(aoa_loc_data[1])

    if index == len(aoa_loc_data[0]):
        return

    azimuth = aoa_loc_data[1][index]
    azimuth = azimuth if (azimuth >= 0) else (azimuth + 360)
    azimuth = azimuth * np.pi / 180.

    distance = aoa_loc_data[0][index]

    azimuth_list.append(azimuth)
    distance_list.append(distance)
    curve.set_data(azimuth_list, distance_list)
    index += 1
    print("azimuth:%f, distance:%f" %(azimuth, distance))

def save_ani_fig(file_name):
    global curve
    global index
    global azimuth_list
    global distance_list
    global aoa_loc_data
    #init
    azimuth_list = []
    distance_list = []
    index = 0
    aoa_loc_data = []

    load_data(file_name)
    fig = plt.figure(file_name)
    pic = fig.add_subplot(111, projection='polar')
    pic.set_title(file_name, va='bottom')
    pic.set_rmax(8)
    pic.set_rticks(np.arange(1, 8, 1))
    pic.set_rlabel_position(0)
    # pic.annotate('a polar annotation',
    #             xy=(0, 0),  # theta, radius
    #             xytext=(0.05, 0.05),    # fraction, fraction
    #             textcoords='figure fraction',
    #             arrowprops=dict(facecolor='black', shrink=0.05),
    #             horizontalalignment='left',
    #             verticalalignment='bottom',
    #             )
    curve, =  pic.plot(azimuth_list, distance_list, linestyle='', marker='*', lw=0.5)
    pic.grid(True)
    ani = FuncAnimation(fig, update_graph, frames=len(aoa_loc_data[0]), interval=20, repeat=False)
    path = os.getcwd()
    #ani_name = path + file_name + '.gif'
    ani_name = os.path.join(path, output_gif, file_name)
    ani_name = ani_name + '.gif'
    ani.save(ani_name, writer='Pillow',fps=40)
    png_name = os.path.join(path, output_png, file_name)
    plt.savefig(png_name)
    #plt.show()

def find_all_file(base):
    for root, dirs, files in os.walk(base):
        for f in files:
            #print(f)
            yield f

if __name__ == '__main__':
    #makedirs() is recursive directory creation function
    os.makedirs(output_png)
    os.makedirs(output_gif)
    os.makedirs(output_csv)
    path = os.getcwd()
    print(path)
    #find_all_file(path)
    for i in find_all_file(path):
        if i.endswith('.log'):
            print(i)
            file_name = os.path.splitext(i)[0]
            save_ani_fig(file_name)
            # path = os.getcwd()
            # # path += "\\dst\\"
            # path = os.path.join(path, "dst", file_name)
            # #ani_name = path + file_name + '.gif'
            # ani_name = path + '.gif'
            # print(ani_name)












import cmath
import re
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import math
from matplotlib.animation import FuncAnimation

distance = 0
azimuth = 0

x_axis = []
y_axis = []

aoa_loc_data = []

index = 0

def create_csv(file_input, line, data):
    global azimuth
    global distance
    ret = 0
    with open(file_input, 'w') as file_ob:
        while line:
            line = data.readline()

            tmp_distance_re = re.search(r'Distance \d+', line)
            tmp_azimuth_re = re.search(r'AoA azimuth -?\d+', line)
            if tmp_distance_re and tmp_azimuth_re:
                distance = int(tmp_distance_re.group(0).replace('Distance ', ''))
                distance /= 100
                azimuth = int(tmp_azimuth_re.group(0).replace('AoA azimuth ', ''))
                #azimuth = 0
                #file_ob.write('%.02f,%d\n' % (distance, azimuth))
                #
                print('原始:%.02fm %d' % (distance, azimuth))
                azimuth = 0 - azimuth;
                print('镜像:%.02fm %d' % (distance, azimuth))
                #azimuth = azimuth if (azimuth >= 0) else (azimuth + 360)
                azimuth = azimuth * np.pi / 180.
                print("弧度:%.02fm %f" % (distance, azimuth))
                file_ob.write('%.02f,%.02f\n' % (distance, azimuth))
                ret = 2
            else:
                ret = 0

def load_file(file_string):
    global filename
    log_file_name = file_string + '.log'
    filename = log_file_name
    filename = file_string + '.csv'
    data = open(log_file_name)
    line = data.readline()
    create_csv(filename, line, data)
    data.close()

def load_data(file_name):
    global aoa_loc_data
    load_file(file_name)
    aoa_loc_data = pd.read_csv(filename, header=None)

    print(len(aoa_loc_data[0]))
    print(len(aoa_loc_data[1]))

    # ax = fig.add_subplot(111, projection='polar')
    # ax.set_rmax(3)
    # # ax.set_rticks(np.arange(1, 10, 1))
    # ax.set_rticks(np.arange(1, 8, 1))
    # ax.set_rlabel_position(0)
    #
    # curve, = ax.plot(aoa_data[0], aoa_data[1], linestyle='', marker='*', lw=0.5)
    # ax.grid(True)


    # for i in range(len(aoa_data[0])):
    #     #print(i)
    #     #print(aoa_data[0][i])
    #     x = aoa_data[0][i] * math.cos(aoa_data[1][i])
    #     y = aoa_data[0][i] * math.sin(aoa_data[1][i])
    #
    #     # x = aoa_data[0][i] * math.cos(math.fabs(aoa_data[1][i]))
    #     # y = aoa_data[0][i] * math.sin(math.fabs(aoa_data[1][i]))
    #
    #     x_axis.append(x)
    #     y_axis.append(y)
    #     print("Distance:%f, AoA:%f, x:%f, y:%f" %(aoa_data[0][i], aoa_data[1][i], x, y))
    # #plt.plot(x_axis, y_axis, 'o', label = "aoa_loc cartesian")
    # plt.scatter(x_axis, y_axis)

def update_graph(step):
    global index
    global pic_plot
    print("index:%d, len:%d" %(index, len(aoa_loc_data[0])))
    if index < len(aoa_loc_data[0]):
        x = aoa_loc_data[0][index] * math.cos(aoa_loc_data[1][index])
        y = aoa_loc_data[0][index] * math.sin(aoa_loc_data[1][index])
        index += 1
        x_axis.append(x)
        y_axis.append(y)
    pic_plot.set_data(x_axis, y_axis)

log_file_name = 'yleft_02'

# gif_name_dict = {"xleft_01": "anchor_left_side_row_scan_01",
#                  "xleft_02": "anchor_left_side_row_scan_02",
#                  "xright_01": "anchor_right_side_row_scan_01",
#                  "xright_02": "anchor_right_side_row_scan_02",
#                  "yleft_01": "anchor_left_side_column_scan_01",
#                  "yleft_02": "anchor_left_side_column_scan_02",
#                  "yright_01": "anchor_right_side_column_scan_01",
#                  "yright_02": "anchor_right_side_column_scan_02"}

gif_name_dict = {"xleft_01": "anchor_right_side_row_scan_01",
                 "xleft_02": "anchor_right_side_row_scan_02",
                 "xright_01": "anchor_left_side_row_scan_01",
                 "xright_02": "anchor_left_side_row_scan_02",
                 "yleft_01": "anchor_right_side_column_scan_01",
                 "yleft_02": "anchor_right_side_column_scan_02",
                 "yright_01": "anchor_left_side_column_scan_01",
                 "yright_02": "anchor_left_side_column_scan_02"}

gif_name = gif_name_dict[log_file_name]

fig = plt.figure("行走轨迹")
pic = fig.add_subplot(111)
pic.set_xlim(-8, 8)
pic.set_ylim(-8, 8)
#pic.grid(True)
plt.title(gif_name)
circle_rad = 15
#plt.annotate('anchor(0,0)', xy=(0, 0), xytext=(0, 0),arrowprops=dict(facecolor='black', shrink=0.05))
plt.annotate("anchor:(%s,%s)" % (0,0), xy=(-2,0), xytext=(-20, 10), textcoords='offset points')
#plt.annotate('anchor', xy=(0,0), xytext=(20,20), textcoords='offset points', color='b', size='large', arrowprops=dict(arrowstyle='simple, tail_width=0.3, head_width=0.8, head_length=0.8', facecolor='b', shrinkB=circle_rad * 1.2))
#plt.annotate('anchor(0,0)', xy=(0,0), xytext=(-2,0),arrowprops={'arrowstyle': '->', 'lw': 4, 'color': 'blue'},va='center')

pic.plot(0, 0, linestyle='', marker='o', lw=0.5, color='r')

pic_plot, = pic.plot(x_axis, y_axis, linestyle='', marker='.', lw=0.5, color='g')
#pic_plot = pic.plot(x_axis, y_axis, 'o', color='r')

load_data(log_file_name)
anim_name = gif_name + '.gif'
anim = FuncAnimation(fig, update_graph, frames=len(aoa_loc_data[0]), interval=10, repeat=False)
#anim.save(anim_name, writer='Pillow',fps=40)
plt.show()




  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2022-05-01 15:44:16  更:2022-05-01 15:47:10 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/26 8:23:22-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码