其他分享
首页 > 其他分享> > scatter legend in matlab

scatter legend in matlab

作者:互联网

在这里插入图片描述

The problem with your code is that h, the output of scatter3, is a single handle. It’s not an array of handles with the same size as your data (which is what you imply when trying to set 40x1 array of labels on it, ignoring irrelevant handle wrapper). And it’s not even an array of two handles as one may have thought (one per color). So you cannot set legend like this. One way around would be to plot all the points of one color at a time:

hFig = figure();
axh = axes(‘Parent’, hFig);
hold(axh, ‘all’);
h1 = scatter3(rand(20,1),rand(20,1),rand(20,1),20,‘b’,‘filled’);
h2 = scatter3(rand(20,1),rand(20,1),rand(20,1),20,‘r’,‘filled’);
view(axh, -33, 22);
grid(axh, ‘on’);
legend(axh, [h1,h2], {‘Alpha’, ‘Beta’});

标签:rand,20,array,scatter,matlab,axh,legend,scatter3
来源: https://blog.csdn.net/Dequn_Teng_CSDN/article/details/116331644