% 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

	
