如何在Matlab中根据值制作2D散点图? [英] How to make 2D scatter plot in Matlab with colors depending on values?

查看:140
本文介绍了如何在Matlab中根据值制作2D散点图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个长度相同的向量:xycls.我想绘制x和y的2D图,但每个点应具有与cls的值相对应的颜色.

I have three vectors of the same lenght: x, y, and cls. I want to make a 2D plot of x and y but each point should have a color corresponding to the value of cls.

我考虑过使用scatter函数,但是您可以改变整个图的颜色,而不是特定元素的颜色.有什么想法吗?

I thought about using the scatter function but you can chage the color of the whole plot, not of particular elements. Any ideas?

cls具有三个值的元素时,我想在本示例中得到类似的东西:

I would like to get something like in this example, when cls has elements of three values:

推荐答案

在分散帮助下:

scatter(x,y,a,c)指定圆形颜色.要绘制所有具有相同颜色的圆,请将c指定为单个颜色字符串或RGB三元组.要使用不同的颜色,请指定c为RGB三元组的向量或三列矩阵.

scatter(x,y,a,c) specifies the circle colors. To plot all circles with the same color, specify c as a single color string or an RGB triplet. To use varying color, specify c as a vector or a three-column matrix of RGB triplets.

您可以将c构造为

c=zeros(size(x),3);
c(cls==1,:)=[1 0 0]; % 1 is red
% ...
scatter(x,y,1,c)

但是,我不知道如何做背景.您是否应用了某种机器学习算法来分类数据?也许您可以得到方程式以绘制背景图,但这取决于方法.

However, I dont know how to do the background. Did you apply some Machine learning algorithm to clasify the data? maybe you can get the equations to plot the background from there, but it depends on the method.

这篇关于如何在Matlab中根据值制作2D散点图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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