Matlab散点图绘制函数scatter用法 您所在的位置:网站首页 matlab散点 Matlab散点图绘制函数scatter用法

Matlab散点图绘制函数scatter用法

2023-08-13 02:35| 来源: 网络整理| 查看: 265

文章目录

展开 常见用法语法说明创建散点图改变圆圈大小改变圆圈颜色填充标记指定标记符号更改标记颜色和线条宽度指定目标坐标区和标记类型创建并修改散点序列 3.5 (4)

今天,带来Matlab中绘制散点图的函数scatter的使用方法。本文,主要介绍scatter函数在Matlab中的常见用法、语法说明、创建散点图、改变圆圈大小、改变圆圈颜色、填充标记、指定标记符号、更改标记颜色和线条宽度、指定目标坐标区和标记类型、创建并修改散点序列等方面的介绍。

它表示因变量随自变量而变化的大致趋势,据此可以选择合适的函数对数据点进行拟合。用两组数据构成多个坐标点,考察坐标点的分布,判断两变量之间是否存在某种关联或总结坐标点的分布模式。散点图将序列显示为一组点。值由点在图表中的位置表示。类别由图表中的不同标记表示。散点图通常用于比较跨类别的聚合数据。

Matlab散点图绘制函数scatter用法

下面我们将开始非常详细的 Matlab scatter 函数语法介绍,实例引用,结果展示。首先,我们给出 Matlab 中关于 scatter 函数的帮助文本如下:

>> help scatter scatter Scatter/bubble plot. scatter(X,Y,S,C) displays colored circles at the locations specified by the vectors X and Y (which must be the same size). S determines the area of each marker (in points^2). S can be a vector the same length a X and Y or a scalar. If S is a scalar, MATLAB draws all the markers the same size. If S is empty, the default size is used. C determines the colors of the markers. When C is a vector the same length as X and Y, the values in C are linearly mapped to the colors in the current colormap. When C is a length(X)-by-3 matrix, it directly specifies the colors of the markers as RGB values. C can also be a color string. See ColorSpec. scatter(X,Y) draws the markers in the default size and color. scatter(X,Y,S) draws the markers at the specified sizes (S) with a single color. This type of graph is also known as a bubble plot. scatter(...,M) uses the marker M instead of 'o'. scatter(...,'filled') fills the markers. scatter(AX,...) plots into AX instead of GCA. H = scatter(...) returns handles to the scatter objects created. Use PLOT for single color, single marker size scatter plots. Example load seamount scatter(x,y,5,z)常见用法scatter(x,y) scatter(x,y,sz) scatter(x,y,sz,c) scatter(___,'filled') scatter(___,mkr) scatter(___,Name,Value) scatter(ax,___) s = scatter(___)语法说明

scatter(x,y) 在向量 x 和 y 指定的位置创建一个包含圆形的散点图。该类型的图形也称为气泡图。

scatter(x,y,sz) 指定圆大小。要绘制大小相等的圆圈,请将 sz 指定为标量。要绘制大小不等的圆,请将 sz 指定为长度等于 x 和 y 的长度的向量。

scatter(x,y,sz,c) 指定圆颜色。要以相同的颜色绘制所有圆圈,请将 c 指定为颜色名称或 RGB 三元组。要使用不同的颜色,请将 c 指定为向量或由 RGB 三元组组成的三列矩阵。

scatter(___,’filled’) 填充圆形。可以将 ‘filled’ 选项与前面语法中的任何输入参数组合一起使用。

scatter(___,mkr) 指定标记类型。

scatter(___,Name,Value) 使用一个或多个名称-值对组参数修改散点图。例如,’LineWidth’,2 将标记轮廓宽度设置为 2 磅。

scatter(ax,___) 将在 ax 指定的坐标区中,而不是在当前坐标区中绘制图形。选项 ax 可以位于前面的语法中的任何输入参数组合之前。

s = scatter(___) 返回 Scatter 对象。在创建散点图后,以后可使用 s 对其进行修改。

创建散点图

创建 x 为 0 和 3π 之间的 200 个等间距值。创建 y 为带随机干扰的余弦值。然后,创建一个散点图。

x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); scatter(x,y)Matlab散点图绘制函数scatter用法改变圆圈大小

使用大小不同的圆圈创建一个散点图。以平方磅为单位指定大小

x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); sz = linspace(1,100,200); scatter(x,y,sz)Matlab散点图绘制函数scatter用法

x、y 和 sz 中的相应元素确定每个圆圈的位置和大小。要按照相同的面积绘制所有圆圈,请将 sz 指定为数值标量。

改变圆圈颜色

创建一个散点图并改变圆圈的颜色。

x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); c = linspace(1,10,length(x)); scatter(x,y,[],c)Matlab散点图绘制函数scatter用法

x、y 和 c 中的相应元素确定每个圆形的位置和颜色。scatter 函数将 c 中的元素映射到当前颜色图中的元素。

填充标记

创建一个散点图并填充标记。scatter 使用标记边的颜色填充每个标记。

x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); sz = 25; c = linspace(1,10,length(x)); scatter(x,y,sz,c,'filled')Matlab散点图绘制函数scatter用法指定标记符号

创建向量 x 和 y,作为带随机干扰的正弦和余弦值。然后,创建一个散点图,并使用面积为 140 平方磅的菱形标记。

theta = linspace(0,2*pi,150); x = sin(theta) + 0.75*rand(1,150); y = cos(theta) + 0.75*rand(1,150); sz = 140; scatter(x,y,sz,'d')Matlab散点图绘制函数scatter用法更改标记颜色和线条宽度

创建向量 x 和 y,作为带随机干扰的正弦和余弦值。创建一个散点图并设置标记边颜色、标记面颜色和线条宽度。

theta = linspace(0,2*pi,300); x = sin(theta) + 0.75*rand(1,300); y = cos(theta) + 0.75*rand(1,300); sz = 40; scatter(x,y,sz,'MarkerEdgeColor',[0 .5 .5],... 'MarkerFaceColor',[0 .7 .7],... 'LineWidth',1.5)Matlab散点图绘制函数scatter用法指定目标坐标区和标记类型

从 R2019b 开始,您可以使用 tiledlayout 和 nexttile 函数显示平铺绘图。调用 tiledlayout 函数以创建一个 2×1 平铺图布局。调用 nexttile 函数以创建坐标区对象 ax1 和 ax2。将在每个坐标区中绘制散点数据。在底部散点图中,指定使用实心菱形标记。

x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); tiledlayout(2,1) % Top plot ax1 = nexttile; scatter(ax1,x,y) % Bottom plot ax2 = nexttile; scatter(ax2,x,y,'filled','d')

由于我用的是Matlab2016,还不支持tiledlayout和nexttile两个函数,所以我这里用subplot函数代替,所用代码如下:

x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); subplot(2,1,1) scatter(x,y) subplot(2,1,2) scatter(x,y,'filled','d')Matlab散点图绘制函数scatter用法创建并修改散点序列

创建一个散点图并返回散点序列对象 s。

theta = linspace(0,1,500); x = exp(theta).*sin(100*theta); y = exp(theta).*cos(100*theta); s = scatter(x,y);Matlab散点图绘制函数scatter用法

在创建散点序列后,使用 s 查询并设置其属性。将线宽设置为 0.6 磅。将标记边颜色设置为蓝色。使用 RGB 三元组颜色设置标记面。

s.LineWidth = 0.6; s.MarkerEdgeColor = 'b'; s.MarkerFaceColor = [0 0.5 0.5];Matlab散点图绘制函数scatter用法

共计4人评分,平均3.5分

到目前为止还没有投票~

很抱歉,这篇文章对您没有用!

让我们改善这篇文章!

告诉我们我们如何改善这篇文章?

转载文章,原文出处:MathWorks官网,由古哥整理发布

如若转载,请注明出处:https://iymark.com/articles/756.html



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有