我有一组预执行的文件,它们没有像.txt
或.csv
或.dat
这样的已知扩展名。它们具有进程名称的扩展,如time0.1 time0.01 ans等等。当我试着读它们,并根据10次方的对数绘制特定的列。当我把文件的内容复制到一个新的文件和扩展名.txt时,我可以绘制图形,但是我有100多个这样的文件,我想把它们一起读,只在一个画布上绘制。找不到文件时出错。我不能复制粘贴每个文件到一个新的文件时,我必须打印它们。有没有可能有一个简单的方法,我可以加载的txt格式是什么,并选择一个特定的列来绘图。我也试过用usecols=(0,1)
和numpy.loadtxt()
一起使用,但每次都显示“file not found error
”。我确实搜索了错误和任何我看到的建议,我做了必要的修改,但仍然是相同的错误。你知道吗
代码:
import numpy as np
import matplotlib.pyplot as plt
from pylab import*
import math
from matplotlib.ticker import LogLocator
for fname in ('threshold0.1_time10', 'threshold0.01_time10', 'threshold0.001_time10', 'threshold0.0001_time10', 'threshold0_time10'):
data = np.loadtxt(fname)
#X=data[0:,]
Y=data[:,2]
plt.plot(Y,':ro')
plt.gca().set_xscale("log")
plt.show()
输入:
1 18683 0.0457805581489
2 3519 0.00862290767681
3 101048 0.247606585657
4 284849 0.697989948517
每个输入文件都有这三列,我只对col[2]
感兴趣
错误
File "read_format.py", line 9, in <module>
data = np.loadtxt("fname", usecols=(0,1,2))
File "/usr/lib/python2.7/dist-packages/numpy/lib/npyio.py", line 690, in loadtxt
fh = iter(open(fname, 'U'))
IOError: [Errno 2] No such file or directory: 'threshold0_time10'
目前没有回答
相关问题 更多 >
编程相关推荐