Change color from red to green in plots
조회 수: 13 (최근 30일)
이전 댓글 표시
Hello, I am trying to change the color of the plot from red to green. But I am not able to figure out the color logic in this code.
I replaced the variables redChannel_ for greenChannel_ respectively and likewise. But I keep getting the same color on my plots.
Here is the original code
%define color for values of CV less than 1 and biger than 1
redChannel_1 = CV(1:60,:)<1;
blueChannel_1 = CV(1:60,:)>1;
redChannel_2 = CV(61:120,:) <1;
blueChannel_2 = CV(61:120,:)> 1;
redChannel_3 = CV(121:180,:) <1;
blueChannel_3 = CV(121:180,:)> 1;
greenChannel_1=blueChannel_1;
colors_1 = double(cat(3, redChannel_1, greenChannel_1, blueChannel_1));
greenChannel_2=blueChannel_2;
colors_2 = double(cat(3, redChannel_2, greenChannel_2, blueChannel_2));
greenChannel_3=blueChannel_3;
colors_3 = double(cat(3, redChannel_3, greenChannel_3, blueChannel_3))
This is the replaced code.
%define color for values of CV less than 1 and bigger than 1
greenChannel_1 = CV(:,1:60) <1;
blueChannel_1 = CV(:,1:60)> 1;
greenChannel_2 = CV(:,61:120) <1;
blueChannel_2 = CV(:,61:120)> 1;
greenChannel_3 = CV(:,121:180) <1;
blueChannel_3 = CV(:,121:180)> 1;
redChannel_1=blueChannel_1;
colors_1 = double(cat(3, greenChannel_1,blueChannel_1,redChannel_1 ));
redChannel_2=blueChannel_2;
colors_2 = double(cat(3, greenChannel_2,blueChannel_2,redChannel_2));
redChannel_3=blueChannel_3;
colors_3 = double(cat(3, greenChannel_3,blueChannel_3, redChannel_3 ));
And this code plots the figures.
set(gcf,'renderer','Painters')
figure(1)
fig1=surf(alpha,gamma,CV(:,1:60),colors_1);
figure(2)
fig1=surf(alpha,gamma,CV(61:120,:),colors_2);
figure(1)
fig1=surf(alpha,gamma,CV(121:180,:),colors_3);
PS:Sorry for the noob question. But I don't figure out how to handle these colors in these plots.
댓글 수: 2
DGM
2023년 2월 11일
편집: DGM
2023년 2월 11일
What exactly are you actually trying to do in the first place? This has errors because the array geometries don't agree, you're overwriting the plots, and the variable names don't correspond to what they actually are. You present two different segmentations of the data, so which one do you want? Also, your CData is cyan and red. Are you calling cyan "green", or do you want green?
채택된 답변
DGM
2023년 2월 11일
I don't have your data, so I'm just generating random ZData and omitting x and y data.
If you only have two color classes, this can simplify by using indexed color instead of generating RGB CData. If you need to reserve the colormap for some other objects in the same axes, you can convert the indexed CData to RGB using ind2rgb().
% some fake data
CV = 2*imgaussfilt(rand(180,180),10);
% define a colormap
CT = [1 0 0; 0 1 0];
% specify region colors as indices into CT
cdata1 = (CV(1:60,:)>1) + 1; % indices start at 1
cdata2 = (CV(61:120,:)>1) + 1;
cdata3 = (CV(121:180,:)>1) + 1;
% plot the things
figure(1)
surf(CV(1:60,:),cdata1);
colormap(CT)
figure(2)
surf(CV(61:120,:),cdata2);
colormap(CT)
figure(3)
surf(CV(121:180,:),cdata3);
colormap(CT)
If you want to change either color, just change the colormap. If just you want to swap the colors, flip the colormap before you use it.
CT = flipud(CT);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!