Reputation: 93
I have a text file that has 6 columns and I want to plot 2 first columns. First of all, I should filter the 6th column to separate values greater than 0.0003 and lower than 0.01 then plotting the rest of the table (the first 2 columns). To elaborate more, first, I want to separate the values of the table by applying a filter on the 6th column, then plotting the remainder of the table.
import numpy as np
import matplotlibe.pyplot as plt
with open('configuration_883.out', 'r') as f:
lines = f.readlines()
near = [float(line.split()[5]) for line in lines]
x = [float(line.split()[0]) for line in lines]
y = [float(line.split()[1]) for line in lines]
xx = []
yy = []
for i in range(1,len(x)):
if all(ii<=1.3 for ii in near):
xx.append(x[i])
yy.append(y[i])
print(xx)
print(yy)
plt.plot(xx,yy)
Upvotes: 0
Views: 38
Reputation: 142651
It seems file uses space as separator so you could use pandas
to read it as CSV
with sep="\s+"
I don't have data to test it but it could be
import numpy as np
import matplotlibe.pyplot as plt
import pandas as pd
df = pd.read_csv('configuration_883.out', sep="\s+", header=None)
print(df)
selected = df[ (df.loc[:,5] > 0.0003) & (df.loc[:,5] < 0.01) ]
print(selected)
plt.plot(selected[0], selected[1])
Upvotes: 1