【问题标题】:Gnuplot histogram plot styleGnuplot 直方图绘图样式
【发布时间】:2019-07-02 17:25:46
【问题描述】:

我有一个这样的数据文件:

PS        105  169 169 169   68  0 0 255    105 169 169 169    0  169 169 169    0   169 169 169    0  169 169 169 
GMQ       43    0  255  0    39  0 0 255    40   34 139  34   105 169 169 169    105 169 169 169    0  169 169 169
GL        81    0  255  0    40  0 0 255    105 169 169 169    0  169 169 169    0   169 169 169    0  169 169 169   
CM_{1}    105  169 169 169   47  0 0 255    105 169 169 169    32 169 169 169    105 169 169 169    0  169 169 169
CM_{2}    105  169 169 169   44  0 0 255    105 169 169 169   105 169 169 169    105 169 169 169    0  169 169 169
P         105  169 169 169   105 0 0 255    105 169 169 169    0  169 169 169    0   169 169 169    0  169 169 169
MH        105  169 169 169   69  0 0 255    105 169 169 169    0  169 169 169    0   169 169 169    0  169 169 169

其中在 2 6 10 14 18 22 列中报告要绘制的值,而在其余列中是 rgb 代码。

我想要一个这样的图形,

使用附加脚本时,条形会叠加:

我应该在脚本中更正什么?

这是 Gnuplot 脚本:

set term pngcairo enhanced size 2560,2048 font "Arial,50"
set output "Hist.png"
set encoding utf8

unset title

set yrange [0.0:150.]
set style data histogram
set style histogram cluster gap 1
set style fill solid
set boxwidth 1.
set xtics format ""
set ylabel "Training Set size [-]"
set grid ytics lw 2 
rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)
unset key

plot "Data.out" u ($0):($2):(0.5):(rgb($3,$4,$5))   :xticlabels(1) w boxes lc rgb variable,\
             "" u ($0):($6):(0.5):(rgb($7,$8,$9))   :xticlabels(1) w boxes lc rgb variable,\
             "" u ($0):($10):(0.5):(rgb($11,$12,$13)):xticlabels(1) w boxes lc rgb variable,\
             "" u ($0):($14):(0.5):(rgb($15,$16,$17)):xticlabels(1) w boxes lc rgb variable,\
             "" u ($0):($18):(0.5):(rgb($19,$20,$21)):xticlabels(1) w boxes lc rgb variable

reset 

感谢您给予我的帮助。

最好的尊重。

【问题讨论】:

  • 删除每条绘图线中的w boxes。它们覆盖了全局设置的直方图样式

标签: gnuplot


【解决方案1】:

根据 gnuplot 演示页面 (http://gnuplot.sourceforge.net/demo/histograms.html),聚类直方图应该是这样绘制的:

plot "Data.out" u 2:xtic(1), '' u 6, '' u 10, '' u 14, '' u 18

但是,我还没有找到根据数据文件中的数据为直方图条单独着色的方法。我的印象是... lc rgb var 不能与直方图样式一起使用(但我可能是错的)。也许有人可以告诉我们。

因此,我建议使用 with boxes 的绘图样式“手动”实现聚类直方图。您定义了一系列要绘制的列ColSequence = "2 6 10 14 18" 和一些其他函数来缩短绘图命令。

代码:

### clustered histograms realized "manually" with boxes
reset session
unset title
unset key

$Data <<EOD
PS        105  169 169 169   68  0 0 255    105 169 169 169    0  169 169 169    0   169 169 169    0  169 169 169 
GMQ       43    0  255  0    39  0 0 255    40   34 139  34   105 169 169 169    105 169 169 169    0  169 169 169
GL        81    0  255  0    40  0 0 255    105 169 169 169    0  169 169 169    0   169 169 169    0  169 169 169   
CM_{1}    105  169 169 169   47  0 0 255    105 169 169 169    32 169 169 169    105 169 169 169    0  169 169 169
CM_{2}    105  169 169 169   44  0 0 255    105 169 169 169   105 169 169 169    105 169 169 169    0  169 169 169
P         105  169 169 169   105 0 0 255    105 169 169 169    0  169 169 169    0   169 169 169    0  169 169 169
MH        105  169 169 169   69  0 0 255    105 169 169 169    0  169 169 169    0   169 169 169    0  169 169 169
EOD

set ylabel "Training Set size [-]"
set yrange [0.0:150.]
set grid ytics lw 2 
set style fill solid 
set boxwidth 1.0
rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)

ColSequence = "2 6 10 14 18"
myBoxWidth = 0.8
Gap = 2
ColCount = int(words(ColSequence))
ColNo(n) = int(word(ColSequence,n))
Color(n) = rgb(column(n+1),column(n+2),column(n+3))
BoxOffset(n) = 1./(ColCount+Gap)*n - 0.5
plot for [i=1:ColCount] $Data u ($0+BoxOffset(i)):(column(ColNo(i))): \
    (1./(ColCount+Gap)*myBoxWidth):(Color(ColNo(i))) w boxes lc rgb var, \
     $Data u 0:(0):xtic(1) w boxes
### end of code

结果:

【讨论】:

  • 感谢您的帮助。该脚本可以正常工作并按我的意愿返回图像。最好的问候
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-28
  • 2013-12-22
  • 1970-01-01
  • 1970-01-01
  • 2020-05-16
  • 2017-08-25
  • 2016-05-27
相关资源
最近更新 更多