Gnuplot CSV - 不同格式的数据

时间:2015-09-07 10:12:21

标签: csv gnuplot

我有一个包含以下格式数据的CSV文件:

Category        X-Axis  Y-Axis
Cat1            100     10.1
Cat1            101     10.12
Cat1            102     8.12

Cat2            100     11.1
Cat2            101     11.31
Cat2            102     12.11

Cat3            100     13.1

我想使用GNUplot生成折线图,但只有当数据交叉选中时,GNUplot才能正确绘制图形:

X-Axis      Cat1        Cat2        Cat3
100         10.1        11.1        13.1
101         10.12       11.31       13.2
102         8.12        12.11       13.3

类别的数量不固定,交叉表将导致太多类别将为null /零值。

有任何建议让GNUPlot绘制线图而不交叉数据吗?

2 个答案:

答案 0 :(得分:1)

确保将每个类别分隔2个或更多空行。

然后用

绘图
plot "gnuplot.dat"  using 2:3:(column(-2)) linecolor variable with lines

它分别使用第2列和第3列表示x,y和伪列(column(-2))。这实际上是对每个数据集的不同内部索引gnuplot的引用。

您可能需要查看详细的gnuplot帮助页面:在gnuplot中输入help plot index

答案 1 :(得分:0)

如果您想要的是与每个类别的键/图例不同的行:

plot for [i=1:no_categories] datafile index i using 2:3 title "Cat".i

(确保数据集之间有两个空行,或使用every