Formatting gnuplot-在饼图中使用Y范围?

Formatting gnuplot-在饼图中使用Y范围?,formatting,gnuplot,offset,pie-chart,Formatting,Gnuplot,Offset,Pie Chart,只有在我不设置yrange的情况下才适用 假设我有一个示例时间概览.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,,,,, TSe

只有在我不设置yrange的情况下才适用

假设我有一个
示例时间概览.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的注释,并注释了
取消设置的边框
,它看起来如下所示:

这很烦人,因为当我尝试添加标签时

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(因为除此之外,代码与链接答案中发布的代码差别不大)


如何让血腥的东西工作?

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

附言:

使用

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。

最好在plot命令之前配置图形属性。其他例程(例如
stats
A_sum
)将受到这些属性的影响(例如
set yrange
)。 这就是饼图消失的原因

另外,确保
x
y
轴的单位长度相等(使用
设置尺寸比-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

在第二张图片中,绘图消失,因为在stats命令之前设置yrange只为stats命令留下TEnq行。然后A_sum=1.118,所有角度都太大,无法绘制。因为他没有明确指定Y范围,所以在第三张图片中剪切了该绘图,因此它会自动缩放到标签绘图。此自动缩放从y=0开始。不设置尺寸比不会导致消失或切割。您通过移动
set yrange
修复了绘图。顺便说一句,我喜欢你的绘图,特别是
中的
左@vagoberto真棒,非常感谢。我是否可以将从文件中提取的标签与百分比连接起来,还是需要绘制另一组标签?@User1291编辑了我的答案。您可以使用
sprintf
连接标签。例如:
sprintf(“%05.2f%%%s”,百分比($2),stringcolumn(1))
将打印类似于
00.13%tPass
的内容。格式
%05.2f
打印一个带2位小数和5个空格的数字。格式
%%
打印符号
%%
%s
打印字符串。