view graphics/multibar.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents 547c48f3a008
children
line wrap: on
line source
% multibar - Multiple bar plots with different domains.
%
% multibar :: plotfn, cells(pair([[N]->Dom],[[N]])), options -> handle.
% plotfn is any plotting function like bar, plot, area stairs etc
% that takes two arrays of X and Y values.
function h=multibar(F,D,varargin)
	X=flatten(foldl(@union,[],map(@fst,D)));
	h=F(X,cellcat(2,map(@(d)expand(X,d),D)),varargin{:});
end

function Y2=expand(X,Data)
	Y2=maprows(@get_or_nan,X);
	function y=get_or_nan(x)
		[dummy,i]=find(Data{1}==x);
		if isempty(i), y=nan; else y=Data{2}(i); end
	end
end