如何在 gnuplot 中制作蜘蛛图?
How to make a spider plot in gnuplot?
假设我的数据是以下形式:
#atom a b c
43 1.2 1.3 1.4
44 1.2 1.4 1.8
45 1.3 1.8 1.9
46 2.0 2.3 2.4
47 1.5 1.6 1.8
我想要这样的情节http://www.r-graph-gallery.com/143-spider-chart-with-saveral-individuals/(中间的那个)。
我该怎么做?
ps。这里的标题 (How to Create a Spider Plot in Gnuplot?) 具有误导性...
据我所知,没有可以直接为您提供链接输出的内置功能。尽管如此,您还是可以使用 Gnuplot 提供的工具进行改进。策略是:
- 分析文件并确定顶点数
- 在参数化模式下生成 "polygonial" 网格
- 使用
filledcurves
绘图样式(透明)绘制数据
例如(数据表示为datablock而不是直接传递一个文件):
reset session
set terminal pngcairo enhanced font "Times,16"
set output 'plot.png'
$DATA << EOD
#atom a b c
43 1.2 1.3 1.4
44 1.2 1.4 1.8
45 1.3 1.8 1.9
46 2.0 2.3 2.4
47 1.5 1.6 1.8
EOD
stats $DATA nooutput
N = STATS_columns
M = STATS_records
set angles degrees
set size ratio -1
set style fill transparent solid 0.25
unset key
unset border
unset xtics
unset ytics
colors = "dark-red royalblue forest-green"
set style line 42 lt 1 lc rgb '#333333' dt 3 lw 0.8
deltaR = 0.5
maxR = 3 + deltaR/4
numOfStepsInR = floor((1.*maxR) / deltaR)
#helper functions
alpha(i) = 90. - i*360./M
posX(i, r) = cos(alpha(i))*r
posY(i, r) = sin(alpha(i))*r
lcolor(i) = word(colors, i%words(colors) + 1)
do for [i=0:M-1] {
stats $DATA every ::i::i using (labelValue=) nooutput
set label sprintf("%d", labelValue) at posX(i,maxR),posY(i,maxR) center offset char posX(i,1),char posY(i,1)
}
do for [j=1:numOfStepsInR] {
set label sprintf("%.1f", j*deltaR) at 0,j*deltaR left offset char 0.5,0 tc rgb '#333333'
}
set parametric
set tr [0:1]
set xr [-1.1*maxR:1.1*maxR]
set yr [-1.1*maxR:1.1*maxR]
plot \
for [i=0:M-1] \
(cos(alpha(i))*(deltaR*(1-t)+t*maxR)),(sin(alpha(i))*(deltaR*(1-t)+t*maxR)) w l ls 42, \
for [i=0:M-1] for [j=1:numOfStepsInR] \
(j*deltaR*cos(alpha(i))*t + (1-t)*j*deltaR*cos(alpha(i+1))),(j*deltaR*sin(alpha(i))*t + (1-t)*j*deltaR*sin(alpha(i+1))) w l ls 42, \
for [i=2:N] $DATA u (posX([=10=], column(i))):(posY([=10=], column(i))) w filledcurves closed fc rgb lcolor(i-2) fs border lc rgb lcolor(i-2) lw 2, \
for [i=2:N] $DATA u (posX([=10=], column(i))):(posY([=10=], column(i))) w p ps 1.2 pt 7 lc rgb lcolor(i-2)
这会产生:
假设我的数据是以下形式:
#atom a b c
43 1.2 1.3 1.4
44 1.2 1.4 1.8
45 1.3 1.8 1.9
46 2.0 2.3 2.4
47 1.5 1.6 1.8
我想要这样的情节http://www.r-graph-gallery.com/143-spider-chart-with-saveral-individuals/(中间的那个)。
我该怎么做?
ps。这里的标题 (How to Create a Spider Plot in Gnuplot?) 具有误导性...
据我所知,没有可以直接为您提供链接输出的内置功能。尽管如此,您还是可以使用 Gnuplot 提供的工具进行改进。策略是:
- 分析文件并确定顶点数
- 在参数化模式下生成 "polygonial" 网格
- 使用
filledcurves
绘图样式(透明)绘制数据
例如(数据表示为datablock而不是直接传递一个文件):
reset session
set terminal pngcairo enhanced font "Times,16"
set output 'plot.png'
$DATA << EOD
#atom a b c
43 1.2 1.3 1.4
44 1.2 1.4 1.8
45 1.3 1.8 1.9
46 2.0 2.3 2.4
47 1.5 1.6 1.8
EOD
stats $DATA nooutput
N = STATS_columns
M = STATS_records
set angles degrees
set size ratio -1
set style fill transparent solid 0.25
unset key
unset border
unset xtics
unset ytics
colors = "dark-red royalblue forest-green"
set style line 42 lt 1 lc rgb '#333333' dt 3 lw 0.8
deltaR = 0.5
maxR = 3 + deltaR/4
numOfStepsInR = floor((1.*maxR) / deltaR)
#helper functions
alpha(i) = 90. - i*360./M
posX(i, r) = cos(alpha(i))*r
posY(i, r) = sin(alpha(i))*r
lcolor(i) = word(colors, i%words(colors) + 1)
do for [i=0:M-1] {
stats $DATA every ::i::i using (labelValue=) nooutput
set label sprintf("%d", labelValue) at posX(i,maxR),posY(i,maxR) center offset char posX(i,1),char posY(i,1)
}
do for [j=1:numOfStepsInR] {
set label sprintf("%.1f", j*deltaR) at 0,j*deltaR left offset char 0.5,0 tc rgb '#333333'
}
set parametric
set tr [0:1]
set xr [-1.1*maxR:1.1*maxR]
set yr [-1.1*maxR:1.1*maxR]
plot \
for [i=0:M-1] \
(cos(alpha(i))*(deltaR*(1-t)+t*maxR)),(sin(alpha(i))*(deltaR*(1-t)+t*maxR)) w l ls 42, \
for [i=0:M-1] for [j=1:numOfStepsInR] \
(j*deltaR*cos(alpha(i))*t + (1-t)*j*deltaR*cos(alpha(i+1))),(j*deltaR*sin(alpha(i))*t + (1-t)*j*deltaR*sin(alpha(i+1))) w l ls 42, \
for [i=2:N] $DATA u (posX([=10=], column(i))):(posY([=10=], column(i))) w filledcurves closed fc rgb lcolor(i-2) fs border lc rgb lcolor(i-2) lw 2, \
for [i=2:N] $DATA u (posX([=10=], column(i))):(posY([=10=], column(i))) w p ps 1.2 pt 7 lc rgb lcolor(i-2)
这会产生: