我一直在使用matplotlib.pyplot.plotfile直接从文件中绘制一些 x,y 值。但是,图中省略了第一个数据行。
我假设绘图文件将第一行视为标题行。有办法阻止这种情况吗?
我发现的对标题解释的唯一引用是在绘图文件文档(上面链接)中,但是我将列索引作为整数元组传递,如下面的语句所示:
plotfile(os.path.join(pathname,'foo.csv'), cols=(3,5), skiprows=0, delimiter=',', label='Series')
提前致谢。
最佳答案
使用 names
关键字参数显式命名列。例如:
plotfile(os.path.join(pathname,'foo.csv'), names=['a', 'b', 'c', 'd', 'e', 'f'], cols=(3,5), skiprows=0, delimiter=',', label='Series')
根据csv2rec
(由 plotfile
使用):
If names is None, a header row is required to automatically assign the recarray names. The headers will be lower cased, spaces will be converted to underscores, and illegal attribute name characters removed. If names is not None, it is a sequence of names to use for the column names. In this case, it is assumed there is no header row.
关于python - Pylabplotfile() 跳过没有标题的文件的第一行 - 如何阻止这个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19019506/