我有一个包含 6 列的文件,我必须绘制 2 个第一列,但要考虑在第 6 列中具有价值的点。第 6 列有很多零和几乎为零的数字,当我放置a[5]>=0时,它也需要一些几乎为零的点,另一方面,不可能进行浮点过滤,我的意思是在 float 数组上应用过滤器。如何应用列表过滤列以提取缓冲区并绘制 X 和 Y。
import numpy as np
import matplotlib.pyplot as plt
import statistics
from statistics import mode
%matplotlib qt
def 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 num
with 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()
大话西游666
相关分类