GNUPLOT每个直方图柱都有不同的颜色

10

我想要将位图文件中不同颜色的数量可视化。

我的数据表看起来像这样:

1 163073164
4 185122087
3 255242000
8 255255255
3 000162232
1 181230029
1 127127127
1 136000021
3 200191231

我想使用gnuplot的直方图样式,用不同的颜色绘制每个颜色条。

我已经尝试使用"lc variable",但它并没有起作用。 :-(

目前我的GNUPLOT脚本:

set style data histograms 
set boxwidth 1
set grid
set style histogram cluster gap 0  
set style fill solid 1.0 border -1
set yrange [0:*]
set xrange [0:*]
set xtics border in scale 0,10  nomirror rotate by -45  offset character 0, 0, 0 left
plot "histo.dat" using 1:xticlabels(2) lc variable no title
#EOF

我遇到了这个错误信息:

gnuplot> plot "histo.dat" using 1:xticlabels(2) lc variable no title
                                              ^
         "histo.plt", line 9: Bad data on line 1

有人能给我一些提示或正确的命令吗?

最好的祝福,Robert

2个回答

22

好问题。我已经使用boxes样式使其工作,而不是您最初使用的histogram样式。我认为这不应该有太大的区别:

set boxwidth 1
set grid
set style fill solid 1.0 border -1
set yrange [0:*]
set xrange [-.5:*]
set xtics border in scale 0,10  nomirror rotate by -45  
plot "histo.dat" using ($0):1:($0):xticlabels(2) w boxes lc variable notitle
                        #^boxes centered on 0,1,2,3,....
                           #^data column
                              #^ linecolor column.  first box has linecolor corresponding to ls 0, second box has linecolor corresponding to ls 1, etc ...
                                   #^ xticlabels (apparently) come last.

如果您对伪列0不熟悉,它(本质上)是数据文件中的行号。我通常不会发布这些东西的输出,但这会生成一个非常丰富多彩的图表!

Colorful bar chart


1

我刚刚编辑了一些内容,现在它可以正常工作了。

set boxwidth 1
set grid
set style fill solid 1.0 border -1
set yrange [0:*]
set xrange [-.5:*]
set xtics border in scale 0,10  nomirror rotate by -45 left
plot "histo.dat" using ($0):1:($2):xticlabels(3) w boxes lc rgb variable notitle
                        #^boxes centered on 0,1,2,3,....
                           #^data column
                              #^ linecolor column.  first box has linecolor corresponding to ls 0, second box has linecolor corresponding to ls 1, etc ...
                                   #^ xticlabels (apparently) come last. 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接