我如何有条件地在matlab中的散点图上的点颜色? [英] How can I conditionally colour points on a scatter plot in matlab?

查看:2348
本文介绍了我如何有条件地在matlab中的散点图上的点颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一组数据上绘制一个绘图(使用散点图或绘图)。
我有一个数据数组,其中包含的值。
我还有一个置信数组,它包含从0到1的值,表示该值的可靠性。
在我的散点图中,我必须用不同的颜色绘制置信度低于0.5的值。

I am trying to draw a plot (using scatter or plot) on a set of data. I have a data array which contains the values. I also have a confidence array which contains values from 0 to 1 to indicate how reliable that value is. In my scatter plot I have to plot the values which have confidence lower than 0.5 in a different colour.

到目前为止,我有:

for i=1:length(data)
    if confidence(i) < 0.5
        colour(i) = 'g';
    else
        colour(i) = 'b';
    end
end

f = figure;
scatter(xvalues,data,[],colour,'x');

问题:

我希望有绿色和蓝色的x,但情节显示全部蓝色。
我检查了有信心值,肯定低于0.5。
我不知道如何指定颜色。

I expect there to be green and blue x's but the plot shows all blue. I have checked that there are confidence values which are definitely lower that 0.5. I am not sure how else to specify the colours.

我使用Matlab R2013a。

I am using Matlab R2013a.

感谢您的帮助。

推荐答案

您应该简单地绘制两次,使用 c $ c>命令:

You should simply plot twice, using the hold on command:

data = rand(10,1);
confidence = rand(10,1);
xvalues = rand(10,1);

f = figure; hold on;
scatter(xvalues(confidence<0.5),data(confidence<0.5),'g');
scatter(xvalues(confidence>=0.5),data(confidence>=0.5),'b');


$ b < (尝试在命令窗口中输入 confidence <0.5 以查看它的功能)。

此外,对于将来,如果你的代码是一个独立的MWE(最低工作示例),它是非常有用的。这意味着也产生一些数据点,所以其他人可以直接复制/粘贴和运行你的代码:)。

Also, for the future, it's very useful if your code is a self-contained MWE (minimum working example). This means also generating some data points, so other people can just copy/paste and run your code directly : ).

这篇关于我如何有条件地在matlab中的散点图上的点颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆