如何使用列值的颜色函数绘制直方图?

发布于 2025-01-31 22:27:00 字数 2155 浏览 3 评论 0原文

我想绘制直方图,但盒子的颜色应该是列内值的功能。如果我的文件的第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(($10)/3600) with histogram notitle ls color(12)


p "< sort 'histo' -k10n" using 12:xticlabels(($10)/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

请有什么想法吗?

I Would like to plot a histogram but the color of my boxes should be function of a value inside a column. If the value in column 12 of my file is egal to 160 the color change in red.

my script :

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(($10)/3600) with histogram notitle ls color(12)


p "< sort 'histo' -k10n" using 12:xticlabels(($10)/3600) with boxes notitle ls color(12)

What I get :

enter image description here

my data :

     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 

and when I use lc rgb variable I get :

boucher.plot", line 12: Not enough columns for variable color

Any ideas please ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅语花开 2025-02-07 22:27:00

我希望这是一个常见的问题,但是,与编写几行代码相比,搜索合适的示例似乎需要更多的时间。
成分是LC RGB变量(检查help variable)和三元操作员(检查help 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

结果:

”在此处输入图像描述”

I expected this to be a frequently asked question, however, it seems it would take more time to search for a suitable example than writing a few lines of code.
The ingredients are lc rgb variable (check help variable) and ternary operator (check help ternary).

Script:

### 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

Result:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文