Prev: SVM For OCR, is it possible to use input methods similar to neural net ?
Next: 64b/66b encoding and scrambling
From: Andrew Stevens on 31 Dec 2009 14:40 Ameya <ameya.r.sathe(a)gmail.com> wrote in message <2fc01b12-edc4-4d8c-bd34-caa24e29dd46(a)n35g2000yqm.googlegroups.com>... > Hello, > > I use a stacked bar plot to represent some data. How can I obtain the > RGB values of the colors that are plotted by default in Matlab? > > For e.g. > data = rand(8,5); > > bar(data,1,'stack') plots the stacked bar graph with the 5 column > values stacked for each row. Thus there are 5 colors in this bar > graph. Matlab uses a default colormap (Jet) to set the colors. > However, when I use cmap = colormap, it displays the default 64 RGB > values from this colormap. > > How can I get the RGB values for the 5 specific colors that are > displayed in the bar graph? > > Thanks and Regards, > Ameya Ameya, My first thought was that the RGB values would be jet(5), but it is not quite right. The objects in the stacked bar graph are just patches and you can contol their properties by getting the children of the bar graph handle. The code below shows how to control the colors of the bars: data = rand(8,10); cmap=hot(size(data,2)); figure bh=bar(data,1,'stack'); ch=get(bh,'children'); cellfun(@(x,y)(set(x,'facecolor',y)),... ch,num2cell(cmap,2)) HTH, Andrew |