Grouping Categories in Scatter Plot
9 views (last 30 days)
Show older comments
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 Comment
dpb
on 21 Feb 2023
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.
Answers (2)
Sulaymon Eshkabilov
on 21 Feb 2023
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 Comments
Star Strider
on 22 Feb 2023
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 Comments
Image Analyst
on 22 Feb 2023
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
on 22 Feb 2023
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.
.
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!