我无法在matlab中获得散点图的图例条目。图例条目在matlab中无法正常工作
对于两种颜色和两种形状的每种组合,我应该有四个不同的条目。
colormap jet
x = rand(1,30); %x data
y = rand(1,30); %y data
c = [1 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 1 1 1 2 2 1 1 1 1 1 2 2 1 1]; %color
s = [2 2 1 1 1 2 1 2 2 1 1 1 1 2 2 2 1 1 1 1 2 2 1 1 1 2 2 1 1 2]; %shape
%index data for each shape (s)
s1 = s == 1; %square
s2 = s == 2; %circle
xsq = x(s1);
ysq = y(s1);
csq = c(s1);
xcirc = x(s2);
ycirc = y(s2);
ccirc = c(s2);
%plot data with different colors and shapes
h1 = scatter(xsq, ysq, 50,csq,'s','jitter','on','jitterAmount',0.2);
hold on
h2 = scatter(xcirc, ycirc, 50, ccirc, 'o','jitter','on','jitterAmount',0.2);
这绘制了散点图,包含红色圆圈和正方形以及蓝色圆圈和正方形。现在我想要一个传说(这不起作用)。
%legend for each combination
legend([h1(1) h1(2) h2(1) h2(2)],'red+square','red+circle','blue+square','blue+circle')
任何想法?谢谢:)
你对“传奇”做过任何研究吗? – MickyD 2015-02-23 05:52:37
@MickyDuncan是的,我已阅读http://au.mathworks.com/help/matlab/ref/legend.html,但似乎无法得到正确的代码 – user2861089 2015-02-23 06:01:20