Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnuplot boxes with different color bars

I want to plot a histogram like chart with boxes. And I hope the bars have different colors. I found some previous cases, use lc rgb variable, but it doesn't work for me. My version is limited to gnuplot4.2. Here is my data sheet:

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

Here is the code part:

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

I want to use the 4th column to denote the bar color. The document said the third number used in using is just the color variable. But it doesn't work for me, the result is no bar produced.

It seems that the using part is quite flexible. I even find some cases in this site put 4 column numbers after using. It is related to different versions?

like image 476
Chris Bao Avatar asked Jan 27 '15 05:01

Chris Bao


1 Answers

Your plot command seems to be wrong. Try the following:

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

It should look like this:

enter image description here

In short about the using 0:2:4:xticlabels(1) part:

  • 0 tells gnuplot to place bars (x value) in the same order as they appear on the file
  • 2 tells gnuplot to take y values from column 2
  • 4 tells gnuplot to take the color variable from the 4th column
  • xticlabels(1) tells gnuplot to take the text labels for the bars from column 1
like image 88
Miguel Avatar answered Oct 05 '22 23:10

Miguel