Change color from red to green in plots

12 次查看(过去 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 个评论
dpb
dpb 2023-2-11
You forgot to attach a .mat file containing CV (at least)
DGM
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
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 CenterFile Exchange 中查找有关 Orange 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by