文章目录
1. 图形对象的理解
图形对象是 MATLAB用来创建可视化数据的组件。每个对象都有一个名为句柄 的唯一标识符。使用该句柄,您可以通过设置对象 属性 来操作现有图形对象的特征
1.1 对象间的层次结构
-
ROOt::即电脑屏幕
-
Figure:图窗(窗口)
- Axes:坐标区 (axis属于axes, 坐标区包含线条、文本、图例以及其他用于表示图形的对象)坐标区是表示 x、 y 和 z 坐标区标 度、刻度线、刻度标签、坐标区标签等对象的单个对象。
-
通常,使用如 plot、bar、scatter等绘图函数创建图形对象。
1.2 对象的查询和修改
点方法
get
set
Example
x = -pi:pi/20:pi;
y = sin(x);
f = figure; % 图窗对象
p = plot(x,y); % 一条线条对象
txt1 = text(0.2,0,'sin(x)'); % 文本对象
% 查询对象的所有属性
get(f)
get(p)
get(txt1)
% 修改对象属性
f.Name = 'PLOT 1'
p.Marker = '*';
txt1.EdgeColor = 'red';
1. plot
2D line plot
Syntax
plot(X,Y)
plot(X,Y,LineSpec)
plot(X1,Y1,...,Xn,Yn)
plot(X1,Y1,LineSpec1,...,Xn,Yn,LineSpecn)
plot(Y)
plot(Y,LineSpec)
plot(___,Name,Value)
plot(ax,___)
h = plot(___)
Input Arguments
- X Y : scale, vector, matrix
- LineSpec: Line style, marker, and color
没有顺序,不必三个全部指定
Line Style | Description |
---|---|
- | Solid line (default) |
- - | Dashed line |
: | Dotted line |
-. | Dash-dot line |
Marker | Description |
---|---|
o | Circle |
+ | Plus sign |
* | Asterisk |
. | Point |
x | Cross |
s | Square |
d | Diamond |
^ | Upward-pointing triangle |
v | Downward-pointing triangle |
> | Right-pointing triangle |
< | Left-pointing triangle |
p | Pentagram |
h | Hexagram |
Color | Description |
---|---|
y | yellow |
m | magenta |
c | cyan |
r | red |
g | green |
b | blue |
w | white |
b | black |
- Name-Value Pair Arguments
Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,…,NameN,ValueN.
Example: ‘Marker’,‘o’,‘MarkerFaceColor’,‘red’
Output Arguments
- h — One or more chart line objects
scalar | vector
One or more chart line objects, returned as a scalar or a vector. These are unique identifiers, which you can use to query and modify properties of a specific chart line. For a list of properties, see Line Properties.
Example
Specify Axes for Line Plot
ax1 = subplot(2,1,1); % top subplot
x = linspace(0,3);
y1 = sin(5*x);
plot(ax1,x,y1)
title(ax1,'Top Subplot')
ylabel(ax1,'sin(5x)')
ax2 = subplot(2,1,2); % bottom subplot
y2 = sin(15*x);
plot(ax2,x,y2)
title(ax2,'Bottom Subplot')
ylabel(ax2,'sin(15x)')
x=(0:pi/100:2*pi)';
y1=2*exp(-0.5*x)*[1,-1];
y2=2*exp(-0.5*x).*sin(2*pi*x);
x1=(0:12)/2;
y3=2*exp(-0.5*x1).*sin(