1

我已成功使用 gnuplot 绘制箱线图。但现在我想坚持使用 gnuplot 来满足我所有的绘图需求,并希望做一些事情,例如。棱镜可以做到:

http://www.graphpad.com/support/faqid/132/

我只有两列数据(之前和之后),并希望所有对都用一条线连接起来。如果有人有任何想法,那就太好了。

4

1 回答 1

2

这不可能开箱即用,因此需要一些摆弄。

  • xtics 是手动设置的,0x'Before' 的 -value,1用于 'After'。这些数值必须在稍后的图中明确使用。

  • 这些线被绘制为arrows没有头。使用lc variable(ie linecolor variable),我们可以使用语句的最后一列using从相应的线型中选择颜色。

  • 首先绘制“之前”点。不幸的是,没有选项pointtype variable,所以我使用plot for迭代为每个点分配不同的pointtype( pt)。

  • 我使用该stats命令来确定要绘制的点数。要获得总数,我必须records将 (内部点)和outofrange点相加,因为分类是根据第一列的值完成的,这与“之前”和“之前”的“手动”xtics 设置冲突后'标签。

这些是要点。当然,还有许多其他可能性(使用线条样式等),但应该是一个很好的起点。

脚本是:

reset
file='beforeafter.txt'

set xtics ('Before' 0, 'After' 1)
set xrange [-0.2:1.2]
set offset 0,0,0.2,0.2

stats file nooutput
cnt = int(STATS_records+STATS_outofrange)

plot for [i=0:cnt-1] file using (0):1 every ::i::i with points lc i+1 pt (6+i) ps 2 t '',\
     for [i=0:cnt-1] file using (1):2 every ::i::i with points lc i+1 pt (6+i) ps 2 t '',\
     file using (0):1:(1):($2-$1):($0+1) with vectors nohead lc variable t ''

用测试数据beforeafter.txt

1  5.5
2  0.3
3  3

你得到结果:

在此处输入图像描述

使用线条样式

另一种变体使用线条样式来设置颜色、线条类型和点类型。对于迭代,您必须明确使用ls (i+1),而对于vectors( as variable) arrowstyle variable,则使用。使用lc variable无法为箭头设置不同的虚线模式。

因此,在我看来,这是一个更具可读性和灵活性的变体:

reset
set termoption dashed
file='beforeafter.txt'

set xtics ('Before' 0, 'After' 1)
set xrange [-0.2:1.2]
set offset 0,0,0.2,0.2

stats file nooutput
cnt = int(STATS_records+STATS_outofrange)

set style line 1 lt 1 pt 5 ps 2 lw 2 lc rgb '#AE1100'
set style line 2 lt 2 pt 7 ps 2 lw 2 lc rgb '#6EB043'
set style line 3 lt 3 pt 9 ps 2 lw 2 lc rgb '#7777ff'

set for [i=1:3] style arrow i ls i nohead

unset key
plot file using (0):1:(1):($2-$1):($0+1) with vectors as variable,\
     for [i=0:cnt-1] file using (0):1 every ::i::i with points ls (i+1),\
     for [i=0:cnt-1] file using (1):2 every ::i::i with points ls (i+1)

结果:

在此处输入图像描述

于 2013-09-12T07:55:15.017 回答