Adjusting plot fill to show two colours depending on overestimation/underestimation
Show older comments
Hello,
I have the following code to plot my observed readings versus my modelled readings and the code works fine but does not clearly show regions where my modelled data is greater than observed data.
% Create figure
figure1 = figure;
XData = mod1_2001_2014(x,1)';
YData1 = mod1_2001_2014(x,5)';
YData2 = mod1_2001_2014(x,4)';
% Plot with fill
X = [XData fliplr(XData)];
Y = [YData1 fliplr(YData2)];
fill(X,Y,[0.678431391716003 0.921568632125854 1]);
ylim([0 max(YData2)+3])
I was wondering if there is a way to have this so that when the YData2 > YData1 the fill is red and when YData1 > YData2, the fill is the colour it is now.
Any ideas? Thank you!
Accepted Answer
More Answers (1)
Luuk van Oosten
on 27 Nov 2014
Dear Massao,
I do not know exactly how your data looks like, but you could use somthing like:
for i=1:lenght(yourdataset)
if YData1 < YData2 % Let matlab check if Ydata2 is larger than YData1
scatter( x(i,1), y(i,5), 15, [1 0 0], 'filled') hold on;
else % if this condition is not matched, then do the following:
scatter( x(i,1), y(i,4),15, [0 0.68 0.92], 'filled') hold on;
end
Have fun!
3 Comments
mashtine
on 27 Nov 2014
Luuk van Oosten
on 27 Nov 2014
Oops, excuse me. I'm not very familiar with plotting lines.
nevertheless, if you try something analogous to
if Ydata1 < Ydata2
fill stuff in fancy blue
else
fill stuff in red
I would expect that to work.
mashtine
on 27 Nov 2014
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!