How do I color an area between 3 graphs ?

1 次查看(过去 30 天)
Jenny
Jenny 2011-3-13
Hi, I have created a plot in which my graph is set up with 2 more graphs serving as upper und lower boundaries (confidence intervals) indicating at which time my graph becomes significant. Now I would like to color the area within the boundaries in a light grey tone, so that I will get a grey "tube" which makes the whole plot visually a bit more appealing. Could anyone give me some advice? My graph is called meanRandLike containing 1000 permutations of my original data and graph. This is the function:
Matlab Code
function [meanRandLike] = Like_Conf(meanRandLike)
s=sort(meanRandLike,2);
bounds = prctile(s',[2.5,97.5]);
%keepvals = s(s>=bounds(1) & s<=bounds(2));
plot(bounds(1,:),'b');
hold on
plot(bounds(2,:),'r');
end

回答(2 个)

Matt Tearle
Matt Tearle 2011-3-13
Something like this?
function [meanRandLike] = Like_Conf(meanRandLike)
s=sort(meanRandLike,2);
bounds = prctile(s',[2.5,97.5]);
x = 1:size(bounds,2);
%keepvals = s(s>=bounds(1) & s<=bounds(2));
plot(x,bounds(1,:),'b',x,bounds(2,:),'r');
patch([x,fliplr(x)],[bounds(1,:),fliplr(bounds(2,:))],...
[0.9,0.9,0.9],'LineStyle','none');
set(gca,'children',flipud(get(gca,'children')))
% just for illustration, let's add the line in the middle
line(x,prctile(s',50),'color','k')

Oleg Komarov
Oleg Komarov 2011-3-13
You can use the fill function:
fill(X,Y,ColorSpec)
Or look at the many submissions on the FEX: confplot
Oleg

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by