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!
