gnuplot - 在饼图中使用 yrange?
gnuplot - making use of the yrange in pie charts?
只有在我不设置 yrange 的情况下才对我有用。
假设我有一个 sample-time-overview.csv
喜欢
,avg,std,,,TProc,2267.5202096317,4573.0532262204
TParse,4.9922379603,138.6595434301,,,,,
THash,86.4020623229,548.8593468508,,,,,
TEnq,1.1181869688,2.0684998031,,,,,
TInQ,1482.2243626062,4257.8024051927,,,,,
TSend,2253.1871161473,4514.2823125251,,,,,
TWait,1.7578696884,43.1050730747,,,,,
TAnsw,14.3452407932,201.9216484892,,,,,
TProcAll,2269.2780793201,4573.3927526674,,,,,
TTotal,3853.3679320114,7095.0740689587,,,,,
我对前两行不感兴趣的地方。
基本上是复制粘贴上面 link 中的代码,稍作调整:
#!/usr/bin/gnuplot
reset
filename = "sample-time-overview"
set terminal pngcairo size 500,500 enhanced font 'Verdana,10'
set output filename."_piechart.png"
#set title ""
unset border
unset tics
set xrange[-1:1.5]
#uncommend yrange and the plotdisappears
#set yrange[-1.25:1.25]
centerX=0
centerY=0
radius=1
set datafile separator ','
set key off
set style fill solid 1
stats filename.".csv" u 2 every ::1::7 noout prefix "A"
angle(x)=x*360/A_sum
percentage(x)=x*100/A_sum
pos=0.0
colour=0
yi=0
plot filename.".csv" u (centerX):(centerY):(radius):(pos):(pos=pos+angle()):(colour=colour+1) every::1::7 w circle lc var
system(sprintf("display %s_piechart.png", filename))
这最终看起来像
我取消注释 yrange 并注释 unset border
,它看起来像这样:
这很烦人,因为当我尝试添加标签时...
plot filename.".csv" u (centerX):(centerY):(radius):(pos):(pos=pos+angle()):(colour=colour+1) every::1::7 w circle lc var,\
"" u (1.5):(yi=yi+0.5/A_records):() every::1::7 w labels
这将会发生:
我怀疑是由于缺少 yrange(因为除此之外,代码与 linked 答案中发布的代码没有太大区别)。
我如何让这该死的东西工作?
设置yrange
也会影响stats
命令的执行。因此,您应该尝试 set yrange[-1.25:1.25]
在 stats
命令之后,而不是在
之前
PS:
使用
绘制标签
plot filename.'.csv' u (1.5):(yi=yi+0.5/A_records):() every::1::7 w labels
对我不起作用。我必须删除美元符号:
plot filename.'.csv' u (1.5):(yi=yi+0.5/A_records):1 every::1::7 w labels
而且我必须稍微调整值 1.5 和 0.5。
最好在 plot 命令之前配置图形属性。其他例程(例如 stats
,因此 A_sum
)将受这些属性(例如 set yrange
)的影响。
这就是饼图消失的原因。
此外,请确保 x
和 y
轴的单位长度相等(使用 set size ratio -1
)。如果不是,圆周将根据 canvas 大小绘制,而不是根据轴绘制。否则饼图将显示为已切掉(除非给出适当的 yrange
)。
经过一些修改,我得到了这个图表:
这是代码:
filename = 'sample-time-overview'
rowi = 1
rowf = 7
# obtain sum(column(2)) from rows 1 to 7
set datafile separator ','
stats filename.'.csv' u 2 every ::rowi::rowf noout prefix "A"
angle(x)=x*360/A_sum
percentage(x)=x*100/A_sum
# circumference dimensions for pie-chart
centerX=0
centerY=0
radius=1
# label positions
yposmin = 0.0
yposmax = 0.95*radius
xpos = 1.5*radius
ypos(i) = yposmax - i*(yposmax-yposmin)/(1.0*rowf-rowi)
#-------------------------------------------------------------------
# now we can configure the canvas
set style fill solid 1 # filled pie-chart
unset key # no automatic labels
unset tics # remove tics
unset border # remove borders; if some label is missing, comment to see what is happening
set size ratio -1 # equal scale length
set xrange [-radius:2*radius] # [-1:2] leaves place for labels
set yrange [-radius:radius] # [-1:1]
#-------------------------------------------------------------------
pos = 0 # init angle
colour = 0 # init colour
# 1st line: plot pie-chart
# 2nd line: draw colored boxes at (xpos):(ypos)
# 3rd line: place labels at (xpos+offset):(ypos)
plot filename.'.csv' u (centerX):(centerY):(radius):(pos):(pos=pos+angle()):(colour=colour+1) every ::rowi::rowf w circle lc var,\
for [i=0:rowf-rowi] '+' u (xpos):(ypos(i)) w p pt 5 ps 4 lc i+1,\
for [i=0:rowf-rowi] filename.'.csv' u (xpos):(ypos(i)):(sprintf('%05.2f%% %s', percentage(), stringcolumn(1))) every ::i+1::i+1 w labels left offset 3,0
假设我有一个 sample-time-overview.csv
喜欢
,avg,std,,,TProc,2267.5202096317,4573.0532262204
TParse,4.9922379603,138.6595434301,,,,,
THash,86.4020623229,548.8593468508,,,,,
TEnq,1.1181869688,2.0684998031,,,,,
TInQ,1482.2243626062,4257.8024051927,,,,,
TSend,2253.1871161473,4514.2823125251,,,,,
TWait,1.7578696884,43.1050730747,,,,,
TAnsw,14.3452407932,201.9216484892,,,,,
TProcAll,2269.2780793201,4573.3927526674,,,,,
TTotal,3853.3679320114,7095.0740689587,,,,,
我对前两行不感兴趣的地方。
基本上是复制粘贴上面 link 中的代码,稍作调整:
#!/usr/bin/gnuplot
reset
filename = "sample-time-overview"
set terminal pngcairo size 500,500 enhanced font 'Verdana,10'
set output filename."_piechart.png"
#set title ""
unset border
unset tics
set xrange[-1:1.5]
#uncommend yrange and the plotdisappears
#set yrange[-1.25:1.25]
centerX=0
centerY=0
radius=1
set datafile separator ','
set key off
set style fill solid 1
stats filename.".csv" u 2 every ::1::7 noout prefix "A"
angle(x)=x*360/A_sum
percentage(x)=x*100/A_sum
pos=0.0
colour=0
yi=0
plot filename.".csv" u (centerX):(centerY):(radius):(pos):(pos=pos+angle()):(colour=colour+1) every::1::7 w circle lc var
system(sprintf("display %s_piechart.png", filename))
这最终看起来像
我取消注释 yrange 并注释 unset border
,它看起来像这样:
这很烦人,因为当我尝试添加标签时...
plot filename.".csv" u (centerX):(centerY):(radius):(pos):(pos=pos+angle()):(colour=colour+1) every::1::7 w circle lc var,\
"" u (1.5):(yi=yi+0.5/A_records):() every::1::7 w labels
这将会发生:
我怀疑是由于缺少 yrange(因为除此之外,代码与 linked 答案中发布的代码没有太大区别)。
我如何让这该死的东西工作?
设置yrange
也会影响stats
命令的执行。因此,您应该尝试 set yrange[-1.25:1.25]
在 stats
命令之后,而不是在
PS:
使用
绘制标签plot filename.'.csv' u (1.5):(yi=yi+0.5/A_records):() every::1::7 w labels
对我不起作用。我必须删除美元符号:
plot filename.'.csv' u (1.5):(yi=yi+0.5/A_records):1 every::1::7 w labels
而且我必须稍微调整值 1.5 和 0.5。
最好在 plot 命令之前配置图形属性。其他例程(例如 stats
,因此 A_sum
)将受这些属性(例如 set yrange
)的影响。
这就是饼图消失的原因。
此外,请确保 x
和 y
轴的单位长度相等(使用 set size ratio -1
)。如果不是,圆周将根据 canvas 大小绘制,而不是根据轴绘制。否则饼图将显示为已切掉(除非给出适当的 yrange
)。
经过一些修改,我得到了这个图表:
这是代码:
filename = 'sample-time-overview'
rowi = 1
rowf = 7
# obtain sum(column(2)) from rows 1 to 7
set datafile separator ','
stats filename.'.csv' u 2 every ::rowi::rowf noout prefix "A"
angle(x)=x*360/A_sum
percentage(x)=x*100/A_sum
# circumference dimensions for pie-chart
centerX=0
centerY=0
radius=1
# label positions
yposmin = 0.0
yposmax = 0.95*radius
xpos = 1.5*radius
ypos(i) = yposmax - i*(yposmax-yposmin)/(1.0*rowf-rowi)
#-------------------------------------------------------------------
# now we can configure the canvas
set style fill solid 1 # filled pie-chart
unset key # no automatic labels
unset tics # remove tics
unset border # remove borders; if some label is missing, comment to see what is happening
set size ratio -1 # equal scale length
set xrange [-radius:2*radius] # [-1:2] leaves place for labels
set yrange [-radius:radius] # [-1:1]
#-------------------------------------------------------------------
pos = 0 # init angle
colour = 0 # init colour
# 1st line: plot pie-chart
# 2nd line: draw colored boxes at (xpos):(ypos)
# 3rd line: place labels at (xpos+offset):(ypos)
plot filename.'.csv' u (centerX):(centerY):(radius):(pos):(pos=pos+angle()):(colour=colour+1) every ::rowi::rowf w circle lc var,\
for [i=0:rowf-rowi] '+' u (xpos):(ypos(i)) w p pt 5 ps 4 lc i+1,\
for [i=0:rowf-rowi] filename.'.csv' u (xpos):(ypos(i)):(sprintf('%05.2f%% %s', percentage(), stringcolumn(1))) every ::i+1::i+1 w labels left offset 3,0