是否可以将xticlabels与splot结合起来?

时间:2014-06-03 15:45:58

标签: gnuplot gnu categorical-data

我有以下数据:

0 FRANCK -0.46
0 JUSSE -1.41
1 JUSSE -0.13
1 FRANCK -2.10

我想做3D图,但我需要显示类别(或标签):

splot "map.gnu" using 1:2:3:yticlabels(2) with points palette pointsize 3 pointtype 7

这给了我一个错误:

 syntax error near unexpected token `('

2 个答案:

答案 0 :(得分:1)

您还必须为y值提供一列。 Gnuplot无法自动生成相同字符串的坐标。但是使用4.6.4我测试你的代码时没有出错,它只告诉我warning: No usable data in this plot to auto-scale axis range. All points x value undefined。如果您提供格式为

的文件
0 0 FRANCK -0.46
0 1 JUSSE -1.41
1 1 JUSSE -0.13
1 0 FRANCK -2.10

并用

绘图
splot "map.gnu" u 1:2:4:yticlabels(3) w p palette ps 3 pt 7

如果与4.6.4一起正常工作。

...我说它不适合您的原始文件吗?这不是完全正确的;)

list = ''
index(w) = words(substr(list, 0, strstrt(list, w)-1))
add_label(d) = (strstrt(list, d) == 0 ? list=list.' '.d : '')

splot 'map.gnu' using (d='|'.strcol(2).'|', add_label(d), $1):(index(d)):3:ytic(2) w p palette ps 3 pt 7

有关解释,请参阅我对Gnuplot, plotting a graph with text on y axis的回答。结果与4.6.4:

enter image description here

我已经看到,使用leftright无法控制ytics的对齐方式。一旦定义了视角,就必须使用offset来校正抽动标签的位置。

答案 1 :(得分:1)

在我看来,在不更改数据文件的情况下最简单的方法是将FRANCKJUSSE等映射到数字数组,该数组允许gnuplot将这些名称解释为数字。理想情况下,您可以定义一个函数map(x),它将名称作为参数并返回一个数字,例如map("FRANCK") = 0map("JUSSE") = 1等:

map(x) = x eq "FRANCK" ? 0 \
: x eq "JUSSE" ? 1 : 1/0 # You can add more names
splot "map.gnu" u 1:(var = strcol(2), map(var)):3:yticlabels(2) \
with points palette pointsize 3 pointtype 7

enter image description here

当然,如果你事先不知道文件中有多少名字和哪些名字,Christoph的回答会更方便。

相关问题