python - Pylabplotfile() 跳过没有标题的文件的第一行 - 如何阻止这个?

标签 python matplotlib

我一直在使用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/

相关文章:

python - 更改散点图标记粗细

python - 属性错误 : module 'matplotlib' has no attribute 'interactive'

python - 更新到最新的 ubuntu 后,我无法访问 mysql...我该怎么办?

python - 创建具有给定行数和重复值的数据框

python - findAll-beautifulsoup-python 无法正常工作

python - 根据RGBA图像 channel 为matplotlib colorbar添加色标

python - 如何构造带 DateOffset 的 TimeGrouper?

python - 尝试在 pytest 屏幕上打印异常错误

python - 导入 matplotlib.pyplot 时如何修复 "UnicodeDecodeError: ' ascii' 编解码器无法解码字节 0xe0"?

python - Matplotlib:绘制离散值