フィルターのクリア

how to specify pcolor color scheme

3 ビュー (過去 30 日間)
ola watad
ola watad 2024 年 6 月 6 日
コメント済み: ola watad 2024 年 6 月 9 日
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

回答 (1 件)

Kevin Holly
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
  1 件のコメント
ola watad
ola watad 2024 年 6 月 9 日
Thank you!!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by