Gnuplot - 带条形标签顺时针旋转 90 度的条形图

问题描述 投票:0回答:1

我有这个 Gnuplot 脚本:

reset session

$Data <<EOD
"Push-Front"            2344 0x289e37
"Push-Back"             187  0x289e37
"Insert"                1222 0x289e37
"Push-Front-Collection" 519  0x289e37
"Push-Back-Collection"  420  0x289e37
"Insert-Collection"     287  0x289e37
"Search"                191  0x28579e
"Pop-Front"             4939 0xa83232
"Pop-Back"              251  0xa83232
"Delete"                4771 0xa83232
"Delete-Range"          345  0xa83232
EOD

set style line 11 lc rgb 0xeeeeee lt 1 lw 1
set style fill solid 1.0
set boxwidth 0.8
set key noautotitle
set ytics 1000
set grid y ls 11
set tics scale 0
set tics out
set xtics rotate by -45
set terminal svg size 450,300 enhanced font "Times New Roman,12"
set output '..\msc-sandbox\TotalDurationBarPlotArrayList.svg'
set yrange[0:5000]
set ylabel "Milliseconds"
plot $Data u 0:2:3:xtic(1) w boxes lc rgb var#, \
        '' u 1:2:3 w labels offset 0,0.7

看起来像这样:

我想要实现的目标是在每个条形的顶部添加条形高度值,顺时针旋转 90 度,以便标签适合绘图。

bar-chart gnuplot
1个回答
0
投票

你没有把自己的价值观放在首位

  1. 因为您以
    w boxes lc rgb var#, \
    结束该行,其中
    #, \
    注释掉了以下行
  2. 值的绘图命令应为
    u 0:2:2
  • 您还可以将 xticlabel 旋转 +45 度或将值的标签旋转 -90 度,然后将其对齐
    right
    left
    。这只是个人阅读偏好的问题。
  • 在顶部添加一些偏移/边距,以获得图表区域内高于该值的数字。

脚本:

### bar chart with rotated xticlabels and values on top
reset session

$Data <<EOD
"Push-Front"            2344 0x289e37
"Push-Back"             187  0x289e37
"Insert"                1222 0x289e37
"Push-Front-Collection" 519  0x289e37
"Push-Back-Collection"  420  0x289e37
"Insert-Collection"     287  0x289e37
"Search"                191  0x28579e
"Pop-Front"             4939 0xa83232
"Pop-Back"              251  0xa83232
"Delete"                4771 0xa83232
"Delete-Range"          345  0xa83232
EOD

set style line 11 lc rgb 0xeeeeee lt 1 lw 1
set style fill solid 1.0
set boxwidth 0.8
set key noautotitle
set ytics 1000
set grid y ls 11
set tics out
set xtics rotate by 45 right
set yrange[0:]
set ylabel "Milliseconds"
set offset 0,0, graph 0.1, 0

plot $Data u 0:2:3:xtic(1) w boxes lc rgb var, \
        '' u 0:2:2 w labels offset 0,0.5 rotate by 90 left
### end of script

结果:

© www.soinside.com 2019 - 2024. All rights reserved.