简体   繁体   English

在MATLAB中绘制无线的2D点

[英]Plotting 2D points without line in MATLAB

I have some 2D points and I want to plot them in MATLAB such that every point has a different color and specifier. 我有一些2D点,我想在MATLAB中绘制它们,以便每个点都有不同的颜色和说明符。 I have used plot function but it creates line whatever you give. 我使用了plot函数,但是无论您给什么,它都会创建线条。 I want to draw these points as discrete points only. 我只想将这些点绘制为离散点。 How can I do that? 我怎样才能做到这一点? Here is what I am trying to achieve in the simplest form (I used TikZ below): 这是我试图以最简单的形式实现的目标(我在下面使用了TikZ):

在此处输入图片说明

UPDATE: Thank you for your comments and answers, I have the following code right now: 更新:感谢您的评论和答复,我现在有以下代码:

x = [  0.56, 0.4526, -0.4324, 0.2749, -0.2993, 0.3404, 0.1959, 0.3363, -0.1706];
y = [0.1999, 0.3939,  0.1999, 0.4414,  0.2000, 0.3931, 0.1999, 0.3966,  0.4056];

figure
plot(x(1),y(1),'rx')
hold on
plot(x(2),y(2),'*','Color','[0 0.9 0]')
hold on
plot(x(3),y(3),'*','Color','[0 0.5 0]')
hold on
plot(x(4),y(4),'o','Color','[0.47 0.52 0.8]','MarkerFaceColor','[0.47 0.52 0.8]')
hold on
plot(x(5),y(5),'o','Color','[0.05 0.28 0.63]','MarkerFaceColor','[0.05 0.28 0.63]')
hold on
plot(x(6),y(6),'s','Color','[1 0.71 0.30]','MarkerFaceColor','[1 0.71 0.30]')
hold on
plot(x(7),y(7),'s','Color','[0.9 0.32 0]','MarkerFaceColor','[0.9 0.32 0]')
%plot(x(7),y(7),'s','Color','[1 0 0.5]','MarkerFaceColor','[1 0 0.5]')
hold on
plot(x(8),y(8),'d','Color','[0.67 0.28 0.73]','MarkerFaceColor','[0.73 0.40 0.78]')
%plot(x(8),y(8),'d','Color','[0.67 0.28 0.73]','MarkerFaceColor','[0.67 0.28 0.73]')
hold on
plot(x(9),y(9),'d','Color','[0.29 0.08 0.55]','MarkerFaceColor','[0.29 0.08 0.55]')
xlabel('X')
ylabel('Y')
h = legend('(^1X,^1Y)','(^2X_1,^2Y_1)','(^2X_2,^2Y_2)','(^3X_1,^3Y_1)','(^3X_2,^3Y_2)','(^4X_1,^4Y_1)','(^4X_2,^4Y_2)','(^5X_1,^5Y_1)','(^5X_2,^5Y_2)');
set(h,'Location','best')
grid

I can now draw the points as dots with different colors and specifiers although this way may not be the best way. 我现在可以将点绘制为具有不同颜色和说明符的点,尽管这种方法可能不是最佳方法。

在此处输入图片说明

You can simply specify the LineSpec option 您只需指定LineSpec选项

http://fr.mathworks.com/help/matlab/ref/plot.html#inputarg_LineSpec http://fr.mathworks.com/help/matlab/ref/plot.html#inputarg_LineSpec

To obtain your example: 要获得您的示例:

plot(xdata, ydata, '.')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM