how to specify pcolor color scheme
5 次查看(过去 30 天)
显示 更早的评论
Hello,
I have 3 matrxies that I want to display using pcolor, where the matrix that identfies the colors, flag1 includes the numbers 1 2 3 - my code right now is as follows-
ma1= pcolor(I0mat,P0mat,flag1);
ma1.FaceAlpha= 0.5;
ma1.EdgeColor='none';
I want to specify 3 colors in the view of pcolor, to ideintfy each number, how do i apply this?
Thank you in advance
0 个评论
回答(1 个)
Kevin Holly
2024-6-6
编辑:Kevin Holly
2024-6-6
% Define the ranges for the variables
I0 = 1:10; % X-axis values
P0 = 1:15; % Y-axis values
% Create meshgrid matrices for the X and Y coordinates
[I0mat, P0mat] = meshgrid(I0, P0);
% Initialize the flag1 matrix with zeros
flag1 = zeros(size(I0mat));
% Fill the flag1 matrix with values 1, 2, and 3 for demonstration
% For instance, divide the matrix into three vertical sections
numCols = size(flag1, 2);
flag1(:, 1:floor(numCols/3)) = 1; % First section with 1s
flag1(:, floor(numCols/3)+1:2*floor(numCols/3)) = 2; % Second section with 2s
flag1(:, 2*floor(numCols/3)+1:end) = 3; % Third section with 3s
% Plot using pcolor
ma1 = pcolor(I0mat, P0mat, flag1);
ma1.FaceAlpha = 0.5;
ma1.EdgeColor = 'none';
figure
% Plot using pcolor
ma1 = pcolor(I0mat, P0mat, flag1);
ma1.FaceAlpha = 0.5;
ma1.EdgeColor = 'none';
% Define a custom colormap
customColormap = [1 0 0; % Red for 1
0 1 0; % Green for 2
0 0 1];% Blue for 3
% Apply the custom colormap
colormap(customColormap);
% Adjust the color limits
caxis([1 3]);
% Optionally, add a colorbar
colorbar('Ticks', [1.33, 2, 2.66], 'TickLabels', {'1', '2', '3'});
See first example in doc
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!