如何在gnuplot中使用其中一列数据作为图例?

时间:2015-04-23 12:30:02

标签: gnuplot

我的数据是这样的:

# c1 c2 c3
23 b 323
23 g 54
23 a 11
23 c 1
23 d 0
23 e 397
23 f 40
24 b 23
24 g 24
24 a 113
24 c 12
24 d 10
24 e 7
24 f 50

我需要在x轴(23,24)上绘制c1,在y轴上绘制c3,以获得不同的c2值,即c2的每个值具有不同颜色的多个图形。

enter image description here

1 个答案:

答案 0 :(得分:2)

一般情况下,你必须在gnuplot之外进行过滤,以便有连接过滤点的线。

如果您知道可以出现在第二列中的所有值,则可以使用Plotting multiple graphs depending on column value with gnuplot中给出的解决方案。

如果您不知道可能的值,可以使用

提取它们
c2s = system("awk '!/^#/ { print $2 }' test.dat | sort | uniq")

然后用

绘制它们
plot for [c2 in c2s] sprintf('< grep ''\b%s\b'' test.dat', c2) using 1:3 with lines title c2

enter image description here