【问题标题】:gnuplot boxes with different color bars具有不同颜色条的 gnuplot 框
【发布时间】:2015-03-25 16:10:44
【问题描述】:

我想绘制一个带框的直方图。我希望酒吧有不同的颜色。我发现了一些以前的案例,使用lc rgb variable,但它对我不起作用。我的版本仅限于 gnuplot4.2。这是我的数据表:

stage          11402.364    100%    1
App1              78.552    0.69%   2
App2           11323.812    99.30%  2
Read               8.469    0.07%   3
Write             41.285    0.04%   3
Repeat          5748.351    50.41%  3
Count           4933.746    43.27%  3
Count_1         3841.355    33.69%  4
Count_2         1092.391    9.59%   4

这里是代码部分:

set boxwidth 0.5 relative 
set style fill solid 0.5
set xtics rotate
plot 'histogramdata_2.txt' using 2:xtic(1):4 with boxes variable lc rgb variable notitle

我想使用第 4 列来表示条形颜色。该文件称using 中使用的第三个数字只是颜色变量。但它对我不起作用,结果是没有产生条形图。

看来using 部分相当灵活。我什至发现这个网站的一些案例在使用后放了 4 个列号。 跟不同版本有关系吗?

【问题讨论】:

  • using 使用的值的数量主要取决于绘图风格。 xtic 部分必须始终排在最后。

标签: gnuplot histogram


【解决方案1】:

您的plot 命令似乎有误。请尝试以下操作:

set boxwidth 0.5 relative 
set style fill solid 0.5
set xtics rotate
plot 'histogramdata_2.txt' using 0:2:4:xticlabels(1) with boxes lc variable

应该是这样的:

简而言之using 0:2:4:xticlabels(1) 部分:

  • 0 告诉 gnuplot 按照它们在文件中出现的顺序放置条形(x 值)
  • 2 告诉 gnuplot 从第 2 列获取 y 值
  • 4 告诉 gnuplot 从第 4 列获取颜色变量
  • xticlabels(1) 告诉 gnuplot 从第 1 列获取条形的文本标签

【讨论】:

  • 您的解决方案对我不起作用。它说“未定义的变量:变量”。所以也许它适用于你的版本。我的版本仅限于 4.2。
  • 您可能在这里遇到了死胡同。我一直在摆弄 4.2,似乎 variable 只能用于尺寸,我未能使其与颜色一起使用。如果可能的话,我的建议是升级你的 gnuplot。
  • 在4.2版本中,使用的第三个数字是boxwidth。因此,如果我按照您的方法“0:2:4:xtics(1)”,生成的条形图颜色相同但宽度不同。
  • @baoqger 如果你只有几种不同的线条颜色,你可以手动编写绘图命令:plot 'histogramdata_2.txt' using ($4 == 1 ? $0 : 1/0):2:xtic(1) with boxes lc 1, '' using ($4 == 2 ? $0 : 1/0):2:xtic(1) with boxes lc 2, ...。不,您不能循环,因为在 4.2 中这是不可能的。或者您可以使用生成绘图命令的外部脚本:cmd = system('generateplot.sh histogramdata_2.txt'); eval(cmd)
  • 是的,我只需要 4 种颜色。我也曾经想过类似的方法。但不确定。在($4 == 1 ? $0 : 1/0) 中,我只能理解一部分,这意味着如果 $4 等于 1 那么 $0 等于 1 否则 $0 等于 0?这是什么意思?
猜你喜欢
  • 2023-03-09
  • 1970-01-01
  • 2017-06-04
  • 1970-01-01
  • 1970-01-01
  • 2012-07-24
  • 1970-01-01
  • 2018-03-05
  • 1970-01-01
相关资源
最近更新 更多