Grouping Categories in Scatter Plot
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello everyone! I have a scatter plot that I am working on and am trying to figure out how to code the groups out. I need different colors to represent different groups. For example Hudson river, Nile river etc. I have 6 rivers. I tried to create a 6x1 line array but that isn't working. Any ideas?
댓글 수: 1
dpb
2023년 2월 21일
As per usual, if you'll share the actual data or something similar, it gets much easier to write specific code.
You can pass either a color triplet array or a vector into the current colormap for each vector using scatter() if you have different vectors for each river or use a given color index/triplet for a specific grouping variable (the river ID) to plot all as a single vector.
plot() will cycle colors for each line in an array treating each column as a separate line; if the data lengths aren't the same for all groups/columns (rivers), then fill in to the length of the longest with NaN; those locations will be transparently ignored.
답변 (2개)
Sulaymon Eshkabilov
2023년 2월 21일
If understood your question correctly, here is one example how to address this issue:
DATA = randi(100, 25, 1);
BIN = discretize(DATA, [1, 20, 41, 61, 81 100], 'categorical',{'Agrade', 'Bgrade', 'Cgrade', 'Dgrade', 'Egrade'});
hist(BIN)
댓글 수: 0
Star Strider
2023년 2월 22일
Is this the correct file? These don’t appear to have anything to do with rivers (although I didn’t look past what’s displayed here) ...
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1303475/WATEDR%20COPY%202.csv', 'VariableNamingRule','preserve')
T1(end-9:end,:)
.
댓글 수: 3
Image Analyst
2023년 2월 22일
So what are the two or three features/values that you will have along each axis in your scatter plot? Do you want a 2-D scatter or 3-D scatter (for 3 features/attributes)
Star Strider
2023년 2월 22일
O.K. I cannot do anything meaningful with the information in that file, so use the link I provided to see if the gscatter function will do what you want.
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Scatter Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
