MATLAB 绘图

这篇博客详细介绍了MATLAB的绘图功能,包括图形对象理解、plot函数的用法、线属性、标签和标题的设置、坐标轴的控制、双Y轴图的创建,以及图形对象属性的查询和修改。内容涵盖了从基本的2D线图到复杂的颜色映射和地理坐标数据,为MATLAB绘图提供全面指导。
摘要由CSDN通过智能技术生成

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(
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值