How to edit my scatter plot legend?
37 views (last 30 days)
I have a problem putting legend on my scatter plot.
I have used legend('Intact','Damage 1','Damage 2','Damage 3');
However, I want 'b*' to be my Intact, 'go' to be my Damage 1, 'k^' to be my Damage 2, and lastly 'rs' to be my Damage 3.
How do I change this?
Please see attached to have better understanding.
I hope I make sense. I really need help with this one
THANK YOU IN ADVANCE!!
dpb on 18 Apr 2016
Edited: dpb on 19 Apr 2016
Need to save the line handles from plot and select one from each group. Each group (column) of points in the plot is a separate line for each group of Y values (one for each X in that dimension of the array) and by default legend begins with the first line and uses the labels given in sequence. Hence, internally the labels as shown in your plot are associated with the first four lines (which are all in the first group/array), not the groups even though there are only four Y arrays. When you don't draw a line between points it's easy to forget the orientation of the lines as plot defines them; to see it, set the line style property on a couple of them and see how the points are then connected.
Since you didn't provide the code in an editable way I'll use an artificial demo instead of trying to type yours in by hand...
>> hL=plot(1:3,rand(4,3),'b*',4:6,rand(4,3),'g^'); % two groups of four, similarly; line save handles
>> xlim([0 7]) % clean up limits for viewing
Select the first line of the two groups of lines; the 4 is number of rows in each group. In the example above I used 3x4 whereas your figure uses 5xN instead; if that were to vary would have to make the selection appropriately for each X grouping.
plot associates the size of the Y array with the appropriate length of the X vector so there are four lines in my case each of length 3.
As noted above, try
to see a particular line and which will make why the above on the legends works to get the desired correlation of line marker to the label works easier to see.
More Answers (1)
Kuifeng on 18 Apr 2016
plot(linspace(1,5,21), Intact..., 'b*',linspace(6,10,21), D1b..., 'go',...
linspace(11,15,21), D2b..., 'k^',linspace(16,20,21), D3b..., 'rs'). %note, may not be 21 elements.