我有一個包含 6 列的文件,我必須繪制 2 個第一列,但要考慮在第 6 列中具有價值的點。第 6 列有很多零和幾乎為零的數字,當我放置a[5]>=0時,它也需要一些幾乎為零的點,另一方面,不可能進行浮點過濾,我的意思是在 float 數組上應用過濾器。如何應用列表過濾列以提取緩沖區并繪制 X 和 Y。import numpy as npimport matplotlib.pyplot as pltimport statistics from statistics import mode %matplotlib qtdef most_frequent(List): counter = 0 num = List[0] for i in List: curr_frequency = List.count(i) if(curr_frequency> counter): counter = curr_frequency num = i return numwith open('file_1001.out', 'r') as f: lines = f.readlines() near = [float(line.split()[5]) for line in lines] #list(filter(lambda near: near = 0, lines)) x = [float(line.split()[0]) for line in lines] y = [float(line.split()[1]) for line in lines]print(most_frequent(near))plt.plot(x[near<=0.0], y[near<=0.0], lw=1.75,label='Points filtered by 6th column= 0')plt.plot(x,y,label='Plot without filter')plt.axis('equal')plt.show()
添加回答
舉報
0/150
提交
取消