How can I make a 2D color plot
3 次查看(过去 30 天)
显示 更早的评论
I have an NxM matrix (B) containing values. Every value N,M corresponds to a value at that position in x,y (similarly, I also have the meshgrids for x and y). What I would like to plot is simply a contour in x,y giving in binary state whether or not the value of B is higher than a threshold. I.e. a plot where every value above threshold gives a red dot and every value below threshold gives a green dot. How do I do this?
Thanks in advance!
回答(1 个)
Star Strider
2018-7-5
Try this:
x = rand(1, 5); % Create Data
y = rand(1, 7); % Create Data
[X,Y] = ndgrid(x,y);
B = rand(5, 7); % Create Data
Bidx = B >= 0.5; % Threshold Index
B1 = B .* Bidx; % Matrix == Threshold Condition
B1(B1 == 0) = NaN; % Only Plot Points Meeting Criteria
B2 = B .* ~Bidx; % Matrix ~= Threshold Condition
B2(B2 == 0) = NaN; % Only Plot Points Meeting Criteria
figure
scatter3(X(:), Y(:), B1(:), '.r')
hold on
scatter3(X(:), Y(:), B2(:), '.g')
hold off
view(0, 90)
2 个评论
Star Strider
2018-7-6
You did not specify the result you wanted.
Try this:
x = rand(1, 50); % Create Data
y = rand(1, 70); % Create Data
[X,Y] = ndgrid(x,y);
B = rand(numel(x), numel(y)); % Create Data
Bidx = B >= 0.5; % Threshold Index
B1 = B .* Bidx; % Matrix == Threshold Condition
figure
hs = surf(X, Y, B1)
set(hs, 'EdgeColor','none')
view(0, 90)
colormap([1 0 0; 0 1 0])
colorbar
Experiment to get different results.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
