Data points in regression with different colors and shapes
Show older comments
Hi everyone,
I would like to know whether there is a way to make the data points have different colors and shapes?
Each data point has 2 attributes. So for example all the points with attribute number 1: equal to "x" I would color them all with red and all points with attribute number 2: equal to "y" I would give them a different shape (square, circle, star, etc.).
Thanks!

Extra details, for the above plot:
I have the following matrix M, rows give the first "attribute" while colomuns give the second "attribute". Then I colapse them into one vector using M=M(:) of size (1 x n )

Then I use these attributes (each correspond to the number of hubs and the number of nodes a newly node is added to of a scale free network, the values in the matrix give the "alpha" parameter of the power law associated to the degree distribution)
I feed the scale free network with both attributes to a function that returns the value "Y" (vector of size 1 x n) on the y-axis.
Then given M and Y, I do the following:
mdl=fitlm(M,Y)
plot(mdl)
8 Comments
Adam Danz
on 22 Oct 2020
You need to tell us how you plotted the data.
Sha
on 22 Oct 2020
dpb
on 22 Oct 2020
...""Y" (vector of size 1 x n) on the y-axis. ...mdl=fitlm(M,Y) ...plot(mdl)"
line attributes are constant for a given line object; and plot creates one line for each vector in the argument list. Hence, in the plot you have created there's only one line object and so it can only have one set of attributes.
In your description of attributes in the array M you state rows are one attribute while columns are another. That implies there are seven (7) row attributes, let's say A, B, C ... G and eight (8) columns, 1 thru 8. Thus, every element in the array has a unique combination of attributes
A1, A2, A3, ... A7,A8
B1, B2, B3, ... B7,B8
...
G1, G2, G3, ... G7,G8
So, the only way to put a unique marker on each element would be to plot each array element separately or use scatter which lets you set a color by element.
Sha
on 22 Oct 2020
Sha
on 22 Oct 2020
Image Analyst
on 22 Oct 2020
Attach your data and code to read it in if you need more help.
dpb
on 22 Oct 2020
Yes, even though all of one row or column may have one attribute in common, the combination is different and so each needs its own handle or the attribute must accept an array of values.
As noted above plot has only one value for both the marker type and color so would have to set each point separately to use it.
scatter allows an array of color triplets so could use it to do all elements in a column with the color for each row and one marker which cuts down the amount of code required by the number of rows.
Why TMW didn't allow the properties to be set within the line object is a real shortcoming; the half-fixed it w/ scatter but only half; the markers can't be set by point. The fact there is such a limited number of markers is annoying, too.
Sha
on 23 Oct 2020
Accepted Answer
More Answers (0)
Categories
Find more on Color and Styling 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!

