这是示例代码:
x = rand(100,1);
y = rand(100,1);
score = rand(100,1);
figure;
colormap(flipud(bone));
caxis([0 1])
axis([0 1 0 1])
scatter(x,y,50,score,'+','LineWidth',2);
legend('scores');
我使用的是反向“骨骼”颜色图,它将纯白色分配给分数值 0,将纯黑色分配给分数值 1。但是,图例似乎会自动分配分数 0,因此如果运行代码,图例颜色为纯白色且不可见。
有什么办法可以解决这个问题吗?谢谢。
如果你只想绘制黑色+
如果不显示数据的颜色范围(与颜色条一样),您可以为此创建一个虚拟图例。这样做的方法如下:
% plot some dummy data for the legend:
scatter(nan,nan,[],1,'+','LineWidth',2)
hold on
% plot your data:
scatter(x,y,50,score,'+','LineWidth',2);
hold off
% add the legend only for the first (dummy) data:
leg = legend('scores');
结果:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)