Scatter with colour-coded markers (matrix)
조회 수: 54 (최근 30일)
이전 댓글 표시
I want to do a scatter with several points x [1303 x 382] and y [1303 x 382]. Each of the points has a different velocity, saved in the matrix velo [1303 x 382].
When I try to do it with scatter(x,y,10,velo), there is an error:
"Color must be one RGB triplet, an m-by-3 matrix of RGB triplets with one color per scatter point, or an m-by-1 vector with one value per scatter point."
How do I do a plot with the points with colour-coded markers based on the velocity?
Thanks for your help!
댓글 수: 0
답변 (3개)
Lateef Adewale Kareem
2022년 6월 5일
편집: Lateef Adewale Kareem
2022년 6월 5일
minv = min(min(velo));
maxv = max(max(velo));
c = (velo - minv)./(maxv - minv);
scatter(x(:),y(:),10,c(:))
댓글 수: 3
Walter Roberson
2022년 6월 5일
This is not needed, scatter uses caxis mapping. And if it were necessary then use rescale() or the older mat2gray()
Adam Danz
2022년 6월 5일
the max(max()), min(min()) caught my eye.
@Lateef Adewale Kareem, since the user wants to represent the velocity using color, and not the normalized velocity, the correct solution is to use the raw velocity values in a vector. Add a colorbar and you'll see the difference. But your converstion to vectors is spot-on.
Walter Roberson
2022년 6월 5일
scatter(x(:), y(:), 10, velo(:))
You might potentially also want to add a caxis() call, if you want to map velocities to consistent colors.
댓글 수: 0
Image Analyst
2022년 6월 5일
편집: Image Analyst
2022년 6월 5일
Try this:
% Initialization Steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
% clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Create sample data because the original poster forgot to.
rows = 3; % or 1303
columns = 382;
markerSize = 15;
x = rand(rows, columns);
y = rand(rows, columns);
numElements = numel(x)
% Make velocity in the range 0-15.
velo = 15 * rand(rows, columns);
% Create a colormap based on velo.
% First sort velo
[sortedVelo, sortOrder] = sort(velo(:), 'ascend');
numDistinctColors = numel(velo)
% Create a generic colormap.
cmap = jet(numDistinctColors);
% Now each row in cmap has c color corresponding to the velo value.
% Plot a scatterplot
scatter(x(:),y(:), markerSize, cmap, 'filled')
% Show the colorbar as a guide to what color is what velocity.
colormap(cmap);
minVelocity = 0
maxVelocity = max(velo(:))
colorbar;
caxis([minVelocity, maxVelocity])
title('Color Coded Velocity', 'FontSize',fontSize)
grid on
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Green에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!