我要创建直方图条形图簇而不使用
set style data histogram
直接用盒子
我没能正确放置不同的线。
这是我的 MWE 和结果
$data <<EOD
jour v0 v1 v2
15-07-2024 3796 5711 151
16-07-2024 2804 4697 154
17-07-2024 2824 4724 155
18-07-2024 2813 4697 150
19-07-2024 1607 2922 154
20-07-2024 2149 4214 153
21-07-2024 1841 3949 151
EOD
set terminal wxt size 1440,800
set key top autotitle columnhead
set title "TST_HISTO"
set style fill solid 1.00 border lt -1
set boxwidth .8
stats $data
ClusterSize = STATS_records
print("clustersize: %d\n", ClusterSize)
xcoord(i) = (i-1)*ClusterSize + column(0)
offset=0
plot for [i=1:3] $data using (xcoord(i)):(column(i+1)) with boxes,\
for [i=1:3] '' using (xcoord(i)):(column(i+1)):i+1 with labels offset 1,1
我的结果::
在这里,我想:
有时编写脚本比在 SO 上搜索它花费的时间更少。我很确定这里发布了类似的任务。好吧,毫不奇怪,我想关于 gnupot 的大多数问题都是关于“直方图”或“条形图”,因为有很多变体(行堆叠、列堆叠、分组、垂直、水平、平面列表、特殊输入数据,排序、着色、标记等)。
检查以下示例。它使用另一个(虚拟)绘图命令来实际绘制任何内容(
NaN
),但绘制组中心的标签。
我想你可以用绘图风格来完成所有这些工作histogram
,但我也经常对所需的数据格式等感到困惑,所以我最终像下面的例子一样“手动”完成它。
脚本:
### plot bar chart without style histogram
reset session
$Data <<EOD
jour v0 v1 v2
15-07-2024 3796 5711 151
16-07-2024 2804 4697 154
17-07-2024 2824 4724 155
18-07-2024 2813 4697 150
19-07-2024 1607 2922 154
20-07-2024 2149 4214 153
21-07-2024 1841 3949 151
EOD
stats $Data skip 1 nooutput
ClusterSize = STATS_records
GroupSize = 3
Gap = 1
set key top autotitle columnheader
set title "TST_HISTO" noenhanced
set style fill solid 1.0 border lt -1
set boxwidth .8
set xrange[:] noextend
set tics out
xPos(i) = (column(0))*(GroupSize + Gap) + i - 1
xCenter(i) = column(0)*(GroupSize + Gap) + (GroupSize - Gap)/2.
plot for [i=1:GroupSize] $Data u (xPos(i)):(column(i+1)) w boxes ti columnheader(i+1), \
for [i=1:GroupSize] '' u (xPos(i)):(column(i+1)):i+1 w labels center offset 0,0.7 , \
'' u (xCenter(0)):(NaN):xtic(1)
### end of script
结果:(wxt 终端尺寸 1000、400)