Peter Bodin


« Earlier1 items total Later »

Change colours in barplot bars

To put separate colorus on a barplot someone might find this helping. The trick is to patch the bars with the color of your choice.


%% Example

n=10; % number of bars
data = ceil(rand(1,n)*36); % some data
x = 1:numel(data); % x

% make a barplot
bh= bar(x, data, 1,'r'); % barplot

% Use "hidden" functions to get the information you want[cax,args,nargs] = axescheck(x, data, 1,'r');
[msg,x,y,xx,yy,linetype,plottype,barwidth,equal]=makebars(args{:});

% Every bar in a bar-plot is made of a set of 5 x-y pairs.
% Create Patch indices
ix=reshape(1:numel(x)*5,5,[]);

% Define RGB-triplets for every 5-set of xy-pairs
col=rand(n,3);

% "Patch it"
for kk=1:numel(args{1})
p(kk)=patch(xx(ix(:,kk)),yy(ix(:,kk)),col(kk,:));
end

« Earlier1 items total Later »




Sponsored by

Sole Central

Your one stop shop for Birkenstock and Crocs shoes and sandles.