MATLAB: Legend Displays Wrong Colors when Plotting Multiple Functions R2015b

legendMATLABr2015b

When trying to display a legend corresponding to a scatter plot, the color of the markers do not correspond to the colors in the plot. If more than one function is plotted on the same axes, the legend will make all markers the color of the most recently plotted function. I have tested this on several computers running 2015b and the error persists. I've tested the exact same code on R2014b and everything works fine.
Sample Code:
x1 = 1:0.2:3;
y1 = 1:0.2:3;
x2 = 5:0.2:7;
y2 = 1:0.2:3;
scatter(x1,y1);
hold on;
scatter(x2,y2);
legend('red','blue');
Any help would be greatly appreciated.

Best Answer

Hi Joseph,
I understand that you are having issues working with legends on scatter plot in MATLAB R2015b.
This is a known issue and there is a bug report which describes the issue and has a work around:
A patch is provided which can be applied by following the instructions in the bug report.
If this still doesnot solve your issue, you can create a Technical Support Request by clicking the link below:
Thanks
Sudhanshu Bhatt
Related Question