Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNUPLOT Each Histogram Bar with different color

I want to visualize the amount of different colors of a bitmap file.

My Datasheet looks like:

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

I want to draw each color bar with its own color by using gnu plot histogram style.

I just try something out by using "lc variable" but it doesnt work. :-(

My GNUPLOT script by now:

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

I've got this error message:

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

Can anybody give me a hint or the correct commands?

Best regards Robert

like image 659
user1553847 Avatar asked Jul 26 '12 07:07

user1553847


2 Answers

Nice question. I've managed to make it work using the boxes style as opposed to the histogram style you were originally using. I don't think that should make too much of a difference though:

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.

If you're unfamiliar with pseudo-column 0, it is (essentially) the line number in the datafile. I don't usually post the output of these things, but this makes one very colorful plot!

Colorful bar chart

like image 146
mgilson Avatar answered Oct 15 '22 23:10

mgilson


I just edit something and now it works.

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. 
like image 1
user1553847 Avatar answered Oct 16 '22 00:10

user1553847