如何使用 gnuplot 绘制格式不友好的数据?

发布于 2024-08-30 09:00:34 字数 523 浏览 4 评论 0原文

我需要绘制一些不完全是最友好格式的数据,大多数示例或用法将内容放在一个很好的列/表中,非常容易解析和绘制图表。不过,我有以下格式(并且对于如何解决这个问题有点困惑):

DATE1 label_1 xx yy
DATE1 label_2 xx yy
DATE1 label_3 xx yy

DATE2 label_2 xx yy
DATE2 label_3 xx yy

DATE3 label_1 xx yy
DATE3 label_2 xx yy
DATE3 label_3 xx yy

DATE4 label_2 xx yy
DATE4 label_3 xx yy
...continues

*我在日期之间添加了额外的空格以提高可读性。

**注意:在 DATE2、DATE4 下,label_1 丢失,即数据文件可能具有来来去去的标签,并且应该表示图形中的不连续性。

我想让 X 轴使用 DATEX 作为标签,然后为每个标签创建两行(分别为 xx 和 yy)。

有人对解决这个问题的最佳方法有什么建议吗?

I need to graph some data that is not exactly in the most friendly format, most examples or usage puts things in a nice column/table that is very easy to parse and graph. However I have the following format (and am a bit stuck as to how to tackle this):

DATE1 label_1 xx yy
DATE1 label_2 xx yy
DATE1 label_3 xx yy

DATE2 label_2 xx yy
DATE2 label_3 xx yy

DATE3 label_1 xx yy
DATE3 label_2 xx yy
DATE3 label_3 xx yy

DATE4 label_2 xx yy
DATE4 label_3 xx yy
...continues

*I've added the extra space between the dates for readability.

**Note: under DATE2,DATE4 label_1 is missing, i.e. the data file may have labels that come and go and should represent a discontinuity in the graph.

I'd like to have the X-axis use the DATEX for the labels, and then create two lines for each label (xx and yy respectively).

Does anyone have any suggestions on the best way to tackle this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戈亓 2024-09-06 09:00:35

你最好的选择可能就是 Gunplot.py (http://gnuplot-py.sourceforge.net/< /a>) 创建一个脚本来执行您需要的任务。然后您可以像在 gnuplot 中一样构建绘图。

    g = Gnuplot.Gnuplot()
    g('set datafile separator " "')
    plot = "plot "
    plot += "'%s' using 1:3 title '($2)' with lines" % (filename))
    plot += ", '%s' using 1:4 title '($2)' with lines" % (filename))
    g(plot)

如果您还没有研究过 gnuplot.py,我肯定会看一下。那里还有一个邮件列表,可能会提供更具体的帮助。

Your best bet might just be to a Gunplot.py (http://gnuplot-py.sourceforge.net/) to create a script that will perform the tasks you need. You can then build the plot as you would in gnuplot.

    g = Gnuplot.Gnuplot()
    g('set datafile separator " "')
    plot = "plot "
    plot += "'%s' using 1:3 title '($2)' with lines" % (filename))
    plot += ", '%s' using 1:4 title '($2)' with lines" % (filename))
    g(plot)

If you haven't looked into gnuplot.py already i'd definitely give it a look. There's a mailing list on there too that might be of more specific help.

黯然 2024-09-06 09:00:35

我不太明白你想要生成什么样的图表。点由两个坐标定义,我可以想象将多个数据集绘制在一起进行比较,这样就可以解释三个参数。第四个适合在哪里?你想要一个聚类直方图吗?

不管怎样,如果我得到的数据格式不适合 gnuplot,我通常会进行一些预处理来为 gnuplot 生成数据文件(使用 Common Lisp 或 Perl)。

更新:根据您的澄清评论,我会将文件转换为以下格式:

# DATE, label-1-x, label-1-y, label-2-x, label-2-y, label-3-x, label-3-y
     1,        xx,        yy,        xx,        yy,        xx,        yy
     .
     .
     .

I don't quite get what kind of graph you want to produce. Points are defined by two coordinates, and I can imagine plotting multiple data sets together for comparison, so that would account for three parameters. Where does the fourth fit in? Do you want a clustered histogram?

Anyway, if the data format I get doesn't suit gnuplot, I usually do some preprocessing to produce the data file for gnuplot (using Common Lisp or Perl).

Update: Following your clarifying comment, I would transform the file into this format:

# DATE, label-1-x, label-1-y, label-2-x, label-2-y, label-3-x, label-3-y
     1,        xx,        yy,        xx,        yy,        xx,        yy
     .
     .
     .
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文