凯鲁嘎吉
用书写铭记日常,最迷人的不在远方

MATLAB实例:二维散点图

作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/

更多请看:随笔分类 - MATLAB作图

    用MATLAB实现简单的散点图的绘制,可以自行设置点的形状与颜色,可以去掉坐标轴边框。

    数据来源:MATLAB高斯混合数据的生成 将二维数据保存为gauss.txt。

1. demo.m

% data_load: https://www.cnblogs.com/kailugaji/p/10861064.html
% data_load: 前两列是二维数据,最后一列是类标签
data_load=dlmread('.\gauss.txt');
figure(1)
plot(data_load(data_load(:, end)==1, 1), data_load(data_load(:, end)==1, 2), 'b.', 'MarkerSize',12 );
hold on
plot(data_load(data_load(:, end)==2, 1), data_load(data_load(:, end)==2, 2), 'r^', 'MarkerSize',6, 'MarkerFaceColor','r');
plot(data_load(data_load(:, end)==3, 1), data_load(data_load(:, end)==3, 2), 'ko', 'MarkerSize',6, 'MarkerFaceColor','g');
plot(data_load(data_load(:, end)==4, 1), data_load(data_load(:, end)==4, 2), 'rp', 'MarkerSize',6, 'MarkerFaceColor','y');
plot(data_load(data_load(:, end)==5, 1), data_load(data_load(:, end)==5, 2), 'mh', 'MarkerSize',6, 'MarkerFaceColor','m');
ylabel('X');
xlabel('Y');
% set(gca,'Visible','off') %去掉横纵坐标边框
saveas(gcf,sprintf('demo_2D.jpg'),'bmp'); %保存图片

2. 结果

去掉边框后:

posted on 2020-06-25 14:27  凯鲁嘎吉  阅读(5345)  评论(2编辑  收藏  举报