如何使用列值的颜色函数绘制直方图?
How to plot histogram with color function of a column value?
我想绘制直方图,但我的框的颜色应该是列内值的函数。如果我的文件第 12 列中的值等于 160,则颜色变为红色。
我的脚本:
set xlabel 'elapsed' font ",14"
set ylabel 'NCPUS' font ",14"
set xtics font "Verdana,12"
set style fill solid border -1
set xtic rotate by -45 scale 0
color(x)=(x==160?1:2)
#p "< sort 'histo' -k10n" using 12:xticlabels(()/3600) with histogram notitle ls color(12)
p "< sort 'histo' -k10n" using 12:xticlabels(()/3600) with boxes notitle ls color(12)
我得到的:
我的数据:
User JobID JobName Partition State Timelimit Start End Elapsed ElapsedRaw NNodes NCPUS NodeList
--------- ------------ ---------- ---------- ---------- ---------- ------------------- ------------------- ---------- ---------- -------- ---------- ---------------
bouchet 6389 E423 epic COMPLETED 365-00:00+ 2022-02-28T20:32:49 2022-03-04T11:24:48 3-14:51:59 312719 5 160 lio[1-5]
6389.batch batch COMPLETED 2022-02-28T20:32:49 2022-03-04T11:24:48 3-14:51:59 312719 1 32 lio1
bouchet 6393 Fenc epic COMPLETED UNLIMITED 2022-03-04T12:08:07 2022-03-05T17:11:00 1-05:02:53 104573 5 160 lio[1-5]
6393.batch batch COMPLETED 2022-03-04T12:08:07 2022-03-05T17:11:00 1-05:02:53 104573 1 32 lio1
bouchet 6399 Fenc epic COMPLETED UNLIMITED 2022-03-05T17:11:12 2022-03-08T10:07:10 2-16:55:58 233758 5 160 lio[1-5]
6399.batch batch COMPLETED 2022-03-05T17:11:12 2022-03-08T10:07:10 2-16:55:58 233758 1 32 lio1
当我使用 lc rgb 变量时,我得到:
boucher.plot", line 12: Not enough columns for variable color
有什么想法吗?
我预计这是一个常见问题,但是,搜索合适的示例似乎比编写几行代码需要更多时间。
成分是lc rgb variable
(检查help variable
)和三元运算符(检查help ternary
)。
脚本:
### variable color with boxes
reset session
# create some random test data
set table $Data
myRandom(n) = int(rand(0)>0.5 ? 160 : rand(0)*160)
plot '+' u 0:(myRandom(0)) w table
unset table
myColor(col) = column(col)>=160 ? 0xff0000 : 0x0ff00
set style fill solid 0.5 border lt -1
set key noautotitle
set xtics out
plot $Data u 1:2:(myColor(2)) w boxes lc rgb var
### end of script
结果:
我想绘制直方图,但我的框的颜色应该是列内值的函数。如果我的文件第 12 列中的值等于 160,则颜色变为红色。
我的脚本:
set xlabel 'elapsed' font ",14"
set ylabel 'NCPUS' font ",14"
set xtics font "Verdana,12"
set style fill solid border -1
set xtic rotate by -45 scale 0
color(x)=(x==160?1:2)
#p "< sort 'histo' -k10n" using 12:xticlabels(()/3600) with histogram notitle ls color(12)
p "< sort 'histo' -k10n" using 12:xticlabels(()/3600) with boxes notitle ls color(12)
我得到的:
我的数据:
User JobID JobName Partition State Timelimit Start End Elapsed ElapsedRaw NNodes NCPUS NodeList
--------- ------------ ---------- ---------- ---------- ---------- ------------------- ------------------- ---------- ---------- -------- ---------- ---------------
bouchet 6389 E423 epic COMPLETED 365-00:00+ 2022-02-28T20:32:49 2022-03-04T11:24:48 3-14:51:59 312719 5 160 lio[1-5]
6389.batch batch COMPLETED 2022-02-28T20:32:49 2022-03-04T11:24:48 3-14:51:59 312719 1 32 lio1
bouchet 6393 Fenc epic COMPLETED UNLIMITED 2022-03-04T12:08:07 2022-03-05T17:11:00 1-05:02:53 104573 5 160 lio[1-5]
6393.batch batch COMPLETED 2022-03-04T12:08:07 2022-03-05T17:11:00 1-05:02:53 104573 1 32 lio1
bouchet 6399 Fenc epic COMPLETED UNLIMITED 2022-03-05T17:11:12 2022-03-08T10:07:10 2-16:55:58 233758 5 160 lio[1-5]
6399.batch batch COMPLETED 2022-03-05T17:11:12 2022-03-08T10:07:10 2-16:55:58 233758 1 32 lio1
当我使用 lc rgb 变量时,我得到:
boucher.plot", line 12: Not enough columns for variable color
有什么想法吗?
我预计这是一个常见问题,但是,搜索合适的示例似乎比编写几行代码需要更多时间。
成分是lc rgb variable
(检查help variable
)和三元运算符(检查help ternary
)。
脚本:
### variable color with boxes
reset session
# create some random test data
set table $Data
myRandom(n) = int(rand(0)>0.5 ? 160 : rand(0)*160)
plot '+' u 0:(myRandom(0)) w table
unset table
myColor(col) = column(col)>=160 ? 0xff0000 : 0x0ff00
set style fill solid 0.5 border lt -1
set key noautotitle
set xtics out
plot $Data u 1:2:(myColor(2)) w boxes lc rgb var
### end of script
结果: