gnuplot的 - 利用该yrange的饼图?(gnuplot - making use of t

2019-09-28 18:04发布

这仅适用于我,如果我没有设置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,,,,,

在那里,我不感兴趣的第一个或最后两行。

基本上复制粘贴的代码从上方轻微调整的链接:

#!/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($2)):(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($2)):(colour=colour+1) every::1::7 w circle lc var,\
                  "" u (1.5):(yi=yi+0.5/A_records):($1) every::1::7 w labels

会出现这种情况:

我怀疑(因为除此之外,该代码没有什么不同从什么是在链接的答案贴出多)是由于缺少yrange。

我如何获得的血腥的东西的工作?

Answer 1:

这是更好只是绘图命令之前配置图形属性。 其它例程(例如stats ,因此A_sum )将由这些特性(例如,受影响set yrange )。 这就是为什么饼图消失。

另外,一定要具有用于相等单元的长度xy轴(使用set size ratio -1 )。 如果不是,则圆周将关于画布大小绘制,并且不与相对于轴。 饼图会出现切割否则(除非适当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($2)):(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($2), stringcolumn(1))) every ::i+1::i+1 w labels left offset 3,0


Answer 2:

设置yrange也影响执行stats命令。 因此,你应该尝试set yrange[-1.25:1.25] stats命令,而不是之前。

PS:

绘制有标签

plot filename.'.csv' u (1.5):(yi=yi+0.5/A_records):($1) 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一点点。



文章来源: gnuplot - making use of the yrange in pie charts?