自动处理测试数据
Chose___B
调试机器人PID的时候发现vex
返回数据只能通过终端输出
这实在是太不便于分析数据了
写了一下程序来把数据转excel
python 版本
1 2 3 4 5 6 7 8 9 10
| import pandas as pd with open('data1.txt', 'r', encoding='utf-8') as f: data0 = f.readlines() title = data0[0].strip('\n').split() data0.pop(0) for i in range(len(data0)): data0[i] = list(map(int,data0[i].strip('\n').split())) df = pd.DataFrame(data0,columns=title) print(df) df.to_excel("data2.xlsx",index=False)
|
不过ChoseB
觉得这样还要打开excel
才可以看图,实在麻烦
又魔改了一下,直接用matplotlib.pyplot
画图
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
| import pandas as pd import matplotlib.pyplot as plt import numpy as np
with open('data.txt', 'r', encoding='utf-8') as f: data0 = f.readlines() title = data0[0].strip('\n').split() data0.pop(0) for i in range(len(data0)): data0[i] = list(map(float,data0[i].strip('\n').split())) df = pd.DataFrame(data0,columns=title) df = df.groupby( title[1] , as_index=False).agg("mean")
plt.figure(figsize=(8,4)) plt.xlabel(title[0]) plt.ylabel("value") str_title = "Image of " for i in title[1::]: if len(str_title)!=9: str_title += ',' str_title += i str_title += " with respect to " str_title += title[0] plt.title(str_title) for i in range(1,len(title)): plt.plot( list(df[ title[0] ]) , list(df[ title[i] ]) , label= title[i]) pass plt.legend() 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
| time x speed 1 0 100 41 0.4 100 70 9.2 100 80 16 100 90 25.6 100 101 36.4 100 110 44.4 100 121 51.2 100 130 58.4 100 140 66 100 150 74 100 161 81.6 100 170 90 100 181 98 100 190 107.2 100 200 117.2 100 210 127.6 100 220 138.4 100 230 149.2 100 240 160 100 250 170.8 100 260 182 100 271 193.2 100 280 204.4 100 290 215.6 100 300 226.8 100 310 238 100 321 249.2 100 330 260.8 100 341 272.4 100 351 284 100 360 295.6 100 370 307.2 100 380 318.8 100 391 324.8 100 400 336.4 100 411 348 100 412 348 100 420 359.6 100 430 371.2 100 440 382.8 100 450 394.4 100 460 406 100 471 417.2 100 481 428.8 100 491 440.4 100 500 451.6 100 510 463.2 100 520 474.8 100 530 486.4 100 540 498 100 550 509.6 100 560 521.2 100 570 533.2 100 581 544.4 100 590 556 100 600 567.6 100 610 579.6 100 620 590.8 100 630 602.4 100 640 614 100 650 625.6 100 660 637.2 100 671 648.8 100 681 660.4 100 690 672 100 701 683.6 100 710 695.6 100 721 707.2 100 731 719.2 100 740 730.8 100 750 742.4 100 760 754 100 770 765.2 100 780 776.4 100 790 788 100 800 799.6 100 810 811.6 100 820 822.8 100 831 834 99.6 841 845.2 92.88 851 857.2 85.68 861 868.4 78.96 871 880 72 882 891.6 65.04 891 903.6 57.84 901 915.2 50.88 911 926.8 43.92 921 938.4 36.96 931 949.6 30.24 941 961.2 23.28 951 972.4 16.56 961 983.6 9.84002 971 994 3.6 980 1003.6 3.6
|