Hello Matlab-Pros
I have a program that should mark certain elements of 3 different graphs if special conditions are met. This conditions can lead to 3 different colors.
To do this I use a custom colormap with exactly 3 colors. If the input actually needs all of this colors it works fine, but if it only needs one color it always uses the middle one.
I put the essential part of the program in the attached script, this should make my problem clear.
How can I always get the colors right?
Best regards and thanks in advance,
Michael
% This one works: (1 = red, 2 = orange, 3 = yellow)
areas = [54 134 1; 354 701 2; 2913 3687 3];% In case the three patches have the same color it doesn't work: (all should be red)
areas = [54 134 1; 354 701 1; 2913 3687 1];% Create Figure and Axes
Figure = figure;subAx1 = subplot(1,3,1);subAx2 = subplot(1,3,2);subAx3 = subplot(1,3,3);xlimit1 = [0.3 0.8];xlimit2 = [20 50];xlimit3 = [0 10000];% This part rearranges 'areas' and 'xlimits' to a way, that 'patch' can work with it
areas(:,1:2) = (areas(:,1:2) - 1)/100;x1 = repmat([xlimit1(1) xlimit1(2) xlimit1(2) xlimit1(1)],size(areas,1),1)';x2 = repmat([xlimit2(1) xlimit2(2) xlimit2(2) xlimit2(1)],size(areas,1),1)';x3 = repmat([xlimit3(1) xlimit3(2) xlimit3(2) xlimit3(1)],size(areas,1),1)';y = repelem(areas(:,1:2)',2,1);% Assign colors tp map
map = [1 0 0 % 1 = red
1 0.5 0 % 2 = orange
1 1 0]; % 3 = yellow
colormap(map)color = areas(:,3);patch(subAx1,x1,y,color, 'FaceAlpha',0.3, 'EdgeColor','none');patch(subAx2,x2,y,color, 'FaceAlpha',0.3, 'EdgeColor','none');patch(subAx3,x3,y,color, 'FaceAlpha',0.3, 'EdgeColor','none');% Set axes limits
subAx1.XLim = xlimit1;subAx2.XLim = xlimit2;subAx3.XLim = xlimit3;subAx1.YLim = [0 80];subAx2.YLim = [0 80];subAx3.YLim = [0 80];
Best Answer