【问题标题】:Plotting using a CSV file使用 CSV 文件绘图
【发布时间】:2013-01-30 01:04:55
【问题描述】:

我有一个 csv 文件,每行有 5 个条目。每个条目都是网络数据包是否被触发。每行的最后一项是数据包的大小。每行 = 以毫秒为单位的时间。

例如行

1 , 0 , 1 , 2 , 117

如何绘制图表,例如其中 x 轴是行号,y 是例如的值每行的第一个条目?

【问题讨论】:

    标签: csv graph gnuplot


    【解决方案1】:

    这应该让你开始:

    set datafile separator ","
    plot 'infile' using 0:1
    

    【讨论】:

    • @mgilson: "," 更好,是的,尽管 Gnuplot 4.7 支持 "comma"。
    • 原来如此。根据我正在使用的机器,我通常使用 4.6 甚至 4.4,因为 4.7 仍在开发中。但有趣的是他们添加了这个。但是,我仍然保留它以供参考或特殊用途:)。我想知道","comma 之间是否有任何细微差别。
    • @mgilson:我不认为有什么区别,src/set.c:2386 读作df_separator = ',';src/set.c:2392 读作df_separator = sep[0]; 在我看来应该是一样的。
    • 根据您的评论,对我来说也一样。我从来没有真正深入挖掘过 gnuplot 源代码(也许我应该在某个时候)。组织得好吗?
    • @mgilson:除了一些空格的烦恼之外,它似乎很可读,并不是我已经挖得很远了。我通过在src/ 中搜索"comma" 找到了上述行:)。
    【解决方案2】:

    您还可以使用 gnuplot(免费)绘制到 png 文件:

    终端命令

    gnuplot> set title '<title>'
    gnuplot> set ylabel '<yLabel>'
    gnuplot> set xlabel '<xLabel>'
    gnuplot> set grid
    gnuplot> set term png
    gnuplot> set output '<Output file name>.png'
    gnuplot> plot '<fromfile.csv>'
    

    注意:您始终需要在set output提供正确的扩展名(此处为.png)@

    那么输出也可能不是行,因为您的数据没有继续。要解决此问题,只需将“情节”行更改为:

    plot '<Fromfile.csv>' with line lt -1 lw 2
    

    更多线条编辑选项(破折号和线条颜色等)位于: http://gnuplot.sourceforge.net/demo_canvas/dashcolor.html

    • gnuplot 在大多数 Linux 发行版中都可以通过包管理器使用(例如,在基于 apt 的发行版上,运行 apt-get install gnuplot
    • gnuplot 可通过 Cygwin 在 windows 中使用
    • gnuplot 可在 macOS 上通过 homebrew 使用(运行 brew install gnuplot

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-09
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多