如何使用 gnuplot 绘制格式不友好的数据?
我需要绘制一些不完全是最友好格式的数据,大多数示例或用法将内容放在一个很好的列/表中,非常容易解析和绘制图表。不过,我有以下格式(并且对于如何解决这个问题有点困惑):
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你最好的选择可能就是 Gunplot.py (http://gnuplot-py.sourceforge.net/< /a>) 创建一个脚本来执行您需要的任务。然后您可以像在 gnuplot 中一样构建绘图。
如果您还没有研究过 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.
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.
我不太明白你想要生成什么样的图表。点由两个坐标定义,我可以想象将多个数据集绘制在一起进行比较,这样就可以解释三个参数。第四个适合在哪里?你想要一个聚类直方图吗?
不管怎样,如果我得到的数据格式不适合 gnuplot,我通常会进行一些预处理来为 gnuplot 生成数据文件(使用 Common Lisp 或 Perl)。
更新:根据您的澄清评论,我会将文件转换为以下格式:
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: