xtic 和 xticlabels 用于在 Gnuplot 中的 x 轴 tics 中绘制字符串

xtic and xticlabels for plotting strings in x-axis tics in Gnuplot

我的数据文件如下

ExpData.dat 
### Units mg/g 
### Col 1-4: Users 1-4 
### Col 5-8: Standard 1 
### Col 9-12: Standard 2
### Col 13-16: Standard 3 
### Col 17-20: Standard 4 
### Col 21-24: Standard 5 
### Col 25-28: Standard 6 
## User 1 User 2 User 3 User 4        User 1 User 2     User 3  User 4   User 1     User 2  User 3  User 4   User 1     User 2  User 3  User 4   User 1     User 2  User 3  User 4   User 1     User 2  User 3  User 4  User 1  User 2  User 3  User 4
User-1 User-2 User-3 User-4        10.07    9.92    9.79    9.68     19.78  19.90   19.38   19.22        39.43  38.35   37.55   37.75        48.95  47.81   46.56   46.23        56.11  56.32   55.04   55.44       67.98   69.39   67.98   67.64
User-1 User-2 User-3 User-4        10.08    9.91    9.82    9.63     19.79  19.92   19.34   19.22        39.45  38.37   37.57   37.70        48.90  47.79   46.58   46.27        56.13  56.35   55.18   55.51       68.02   69.45   67.78   67.60
User-1 User-2 User-3 User-4        10.02    9.92    9.76    9.64     19.75  19.91   19.33   19.25        39.41  38.41   37.58   37.68        48.92  47.81   46.63   46.24        56.13  56.41   55.27   55.63       68.00   69.38   67.86   67.68
User-1 User-2 User-3 User-4        10.04    9.92    9.86    9.64     19.79  19.93   19.33   19.21        39.45  38.35   37.57   37.61        48.92  47.78   46.68   46.26        56.13  56.34   55.02   55.57       68.04   69.42   67.68   67.83
User-1 User-2 User-3 User-4        10.01    9.89    9.76    9.69     19.74  19.94   19.30   19.20        39.47  38.34   37.53   37.78        48.97  47.81   46.74   46.22        56.18  56.37   55.10   55.46       68.12   69.41   67.76   67.44
User-1 User-2 User-3 User-4        10.06    9.88    9.79    9.71     19.79  19.94   19.35   19.20        39.49  38.41   37.58   37.72        48.90  47.81   46.64   46.29        56.14  56.35   54.98   55.50       68.12   69.38   68.03   67.72

现在我想要一个散点图,其中 User-1、User-2、User-3 和 User-4 作为 x-tics。绘制直方图似乎很容易,但我在绘制散点图时遇到了一个小问题。下面给出了仅为 User-1 和 User-2 绘制数据的测试代码(User-1 和 User-2 作为 x-tics)

##
##
reset session 
##
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 4in,3in  
set output "ExpData.eps"
#
set xtics out scale 1.5 
set ytics out scale 1.5
set tics font ", 14"
set xlabel "Users" font ",16"
set ylabel "mg U/g" font ",16"
set key inside top right title "Experimental Data" font ",14" 
set yrange [0:75] 
#
plot 'ExpData.dat' u 5:xtic(1) w points pt 10 ps 1.50 lt rgb "#0000FF" notitle, \
'' u 9:xticlabels(1)  w points pt 10 ps 1.50 lt rgb "#006400" notitle, \
'' u 13:xticlabels(1) w points pt 10 ps 1.50 lt rgb "#9932CC" notitle, \
'' u 17:xticlabels(1) w points pt 10 ps 1.50 lt rgb "#9932CC" notitle, \
'' u 21:xticlabels(1) w points pt 10 ps 1.50 lt rgb "#FF0000" notitle, \
'' u 25:xticlabels(1) w points pt 10 ps 1.50 lt rgb "#FFD700" notitle, \
###
'' u 6:xtic(2)  w points pt 8 ps 1.50 lt rgb "#0000FF" notitle, \
'' u 10:xticlabels(2) w points pt 8 ps 1.50 lt rgb "#006400" notitle, \
'' u 14:xticlabels(2) w points pt 8 ps 1.50 lt rgb "#9932CC" notitle, \
'' u 18:xticlabels(2) w points pt 8 ps 1.50 lt rgb "#9932CC" notitle, \
'' u 22:xticlabels(2) w points pt 8 ps 1.50 lt rgb "#FF0000" notitle, \
'' u 26:xticlabels(2) w points pt 8 ps 1.50 lt rgb "#FFD700" notitle, \
###

代码以错误“无效命令”结束。是不是数据文件或代码有问题,谁能指点一下。

Revision of question after response of @theozh

我需要的是

我)。 x 轴应该只有 4 个抽动点;用户 1、用户 2、用户 3 和用户 4。

ii).对于用户 1,应该在不同的 y 范围内绘制 6 组 6 个点(用户 1 的第 5、9、13、17、21 和 25 列)。对于每一列,pointtype 已在代码中定义。例如 User-1

plot 'ExpData.dat' u 5:xtic(1) w p pt 10 ps 1.50 lt rgb "#0000FF", \
'' u 9:xtic(1)  w p pt 10 ps 1.50 lt rgb "#006400", \
'' u 13:xtic(1) w p pt 10 ps 1.50 lt rgb "#9932CC", \
'' u 17:xtic(1) w p pt 10 ps 1.50 lt rgb "#9932CC", \
'' u 21:xtic(1) w p pt 10 ps 1.50 lt rgb "#FF0000", \
'' u 25:xtic(1) w p pt 10 ps 1.50 lt rgb "#FFD700", \

但它导致用户 1 有 6 次抽动,而不是一次抽动。

iii).下面给出了完整的代码,但它只给出了 User-4 的 6 个技巧。

##
##
reset session 
##
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 4in,3in  
set output "ExpData.eps"
# FOR CUSTOM LINESTYLES
set style line 1 lt 2 lw 4 lc rgb "#0000FF"
set style line 2 lt 2 lw 4 lc rgb "#006400"
set style line 3 lt 2 lw 4 lc rgb "#9932CC"
set style line 4 lt 2 lw 4 lc rgb "#120A8F"
set style line 5 lt 2 lw 4 lc rgb "#FF0000"
set style line 6 lt 2 lw 4 lc rgb "#FFD700"
set style line 7 lt 2 lw 4 lc rgb "#8470FF"
set style line 8 lt 2 lw 4 lc rgb "#5D478B"
set style line 9 lt 2 lw 4 lc rgb "#9370DB"
set style line 10 lt 2 lw 4 lc rgb "black" 
set key samplen 4 spacing 1.4 font ",14" width -2
#
set xtics out scale 1.5 
set ytics out scale 1.5
set tics font ", 14"
set xlabel "Users" font ",16"
set ylabel "mg/g" font ",16"
set key inside bottom right spacing 1.35 font ",12" noautotitle 
set key title "Experimental Data" font ",14" 
set yrange [0:75] 
#
plot 'ExpData.dat' u 5:xtic(1) w p pt 10 ps 1.50 lt rgb "#0000FF", \
'' u 9:xtic(1)  w p pt 10 ps 1.50 lt rgb "#006400", \
'' u 13:xtic(1) w p pt 10 ps 1.50 lt rgb "#9932CC", \
'' u 17:xtic(1) w p pt 10 ps 1.50 lt rgb "#9932CC", \
'' u 21:xtic(1) w p pt 10 ps 1.50 lt rgb "#FF0000", \
'' u 25:xtic(1) w p pt 10 ps 1.50 lt rgb "#FFD700", \
'' u 6:xtic(2)  w p pt 8 ps 1.50 lt rgb "#0000FF", \
'' u 10:xtic(2) w p pt 8 ps 1.50 lt rgb "#006400", \
'' u 14:xtic(2) w p pt 8 ps 1.50 lt rgb "#9932CC", \
'' u 18:xtic(2) w p pt 8 ps 1.50 lt rgb "#9932CC", \
'' u 22:xtic(2) w p pt 8 ps 1.50 lt rgb "#FF0000", \
'' u 26:xtic(2) w p pt 8 ps 1.50 lt rgb "#FFD700", \
'' u 7:xtic(3) w p pt 6 ps 1.50 lt rgb "#0000FF", \
'' u 11:xtic(3) w p pt 6 ps 1.50 lt rgb "#006400", \
'' u 15:xtic(3) w p pt 6 ps 1.50 lt rgb "#9932CC", \
'' u 19:xtic(3) w p pt 6 ps 1.50 lt rgb "#9932CC", \
'' u 23:xtic(3) w p pt 6 ps 1.50 lt rgb "#FF0000", \
'' u 27:xtic(3) w p pt 6 ps 1.50 lt rgb "#FFD700", \
'' u 8:xtic(4) w p pt 4 ps 1.50 lt rgb "#0000FF", \
'' u 12:xtic(4) w p pt 4 ps 1.50 lt rgb "#006400", \
'' u 16:xtic(4) w p pt 4 ps 1.50 lt rgb "#9932CC", \
'' u 20:xtic(4) w p pt 4 ps 1.50 lt rgb "#9932CC", \
'' u 24:xtic(4) w p pt 4 ps 1.50 lt rgb "#FF0000", \
'' u 28:xtic(4) w p pt 4 ps 1.50 lt rgb "#FFD700"
### End of code 

你的问题在这里:

'' u 25:xticlabels(1) w points pt 10 ps 1.50 lt rgb "#FFD700" notitle, \
###
'' u 6:xtic(2)  w points pt 8 ps 1.50 lt rgb "#0000FF" notitle, \

字符 \ 继续第 1 行。如果第 2 行以 # 开头,这将是注释。 如果您不以 \ 结束此行,第 3 行将是一个新命令,但 '' u 6:... 是无效命令,因为它不再“连接”到原始绘图命令。但是,即使您在第 2 行的末尾添加 \,其余所有行都将被解释为注释。检查 help comments.

因此,删除 ###。它对于视觉结构和格式可能很好,但在 plot 命令中不起作用(仅在最后)。

顺便说一句,你可以缩短一些命令,让你的绘图命令更短更清晰。

  • xticlabels() --> xtic()
  • with points --> w p
  • set key noautotile 而不是在每个 sub-plot 命令中重复 notitle

这就是您消除错误的方式。但是您的情节中的其他内容似乎不正确。也许您可以更详细地解释您希望如何与用户一起使用 xtic 标签。

编辑:(OP 编辑​​问题后)

您可以在绘图命令中使用循环,这可能会让您的生活更轻松、更短。您可以循环用户和每个用户的情节数量。您为点类型、颜色和数据列定义了一些函数。然后使用变量 pointtype pt var 和变量 linecolor lc rgb var。检查 help variable。我试着用你的数据来做这件事。 虽然,我怀疑你想应用相同的颜色 0x9932cc 两次,但这很容易改变。

代码:

### plot command does not allow for commented lines inbetween
reset session 

$Data <<EOD
## User 1 User 2 User 3 User 4        User 1 User 2     User 3  User 4   User 1     User 2  User 3  User 4   User 1     User 2  User 3  User 4   User 1     User 2  User 3  User 4   User 1     User 2  User 3  User 4  User 1  User 2  User 3  User 4
User-1 User-2 User-3 User-4        10.07    9.92    9.79    9.68     19.78  19.90   19.38   19.22        39.43  38.35   37.55   37.75        48.95  47.81   46.56   46.23        56.11  56.32   55.04   55.44       67.98   69.39   67.98   67.64
User-1 User-2 User-3 User-4        10.08    9.91    9.82    9.63     19.79  19.92   19.34   19.22        39.45  38.37   37.57   37.70        48.90  47.79   46.58   46.27        56.13  56.35   55.18   55.51       68.02   69.45   67.78   67.60
User-1 User-2 User-3 User-4        10.02    9.92    9.76    9.64     19.75  19.91   19.33   19.25        39.41  38.41   37.58   37.68        48.92  47.81   46.63   46.24        56.13  56.41   55.27   55.63       68.00   69.38   67.86   67.68
User-1 User-2 User-3 User-4        10.04    9.92    9.86    9.64     19.79  19.93   19.33   19.21        39.45  38.35   37.57   37.61        48.92  47.78   46.68   46.26        56.13  56.34   55.02   55.57       68.04   69.42   67.68   67.83
User-1 User-2 User-3 User-4        10.01    9.89    9.76    9.69     19.74  19.94   19.30   19.20        39.47  38.34   37.53   37.78        48.97  47.81   46.74   46.22        56.18  56.37   55.10   55.46       68.12   69.41   67.76   67.44
User-1 User-2 User-3 User-4        10.06    9.88    9.79    9.71     19.79  19.94   19.35   19.20        39.49  38.41   37.58   37.72        48.90  47.81   46.64   46.29        56.14  56.35   54.98   55.50       68.12   69.38   68.03   67.72
EOD

set xtics out scale 1.5 
set ytics out scale 1.5
set tics font ", 14"
set xlabel "Users" font ",16"
set ylabel "mg U/g" font ",16"
set key inside top right title "Experimental Data" font ",14" noautotitle
set yrange [0:75] 

myPoints(n)      = int(word("10 8 6 4",n))   # different pointtypes
myColor(n)       = int(word("0x0000ff 0x006400 0x9932cc 0x9932cc 0xff0000 0xffd700",i))
myColumn(user,n) = column(user + n*4)

set xrange[0.5:4.5]
plot for [user=1:4] for [i=1:6] \
     $Data u (user):(myColumn(user,i)):(myPoints(user)):(myColor(i)):xtic(user) \
     w p pt var ps 1.50 lc rgb var
### end of code

结果: