Python Plot After String
I want to plot data from .dat file. But this .dat file starts with string. For example, My file includes col 1 col 2 col 3 and I want to read under the col 3 data. I want skip two
Solution 1:
Since you are already importing numpy
, you could use np.genfromtext
here to make things a lot simpler, since it has the option skip_header
which tells it how many header rows to skip.
import matplotlib.pyplot as plt
import numpy as np
data = np.genfromtxt('input.dat', skipheader=2)
xv = data[:, 2]
plt.plot(xv)
plt.show()
Or, if you only need to read in column 3:
import matplotlib.pyplotas plt
import numpy as np
xv = np.genfromtxt('input.dat', skipheader=2, usecols=(2,))
plt.plot(xv)
plt.show()
Post a Comment for "Python Plot After String"