个性化阅读
专注于IT技术分析

MATLAB 2D基本图形绘制

本文概述

目的:研究图形, 即二维绘图, 打印标签, 网格和轴框, 绘图中的文本, 条形图和饼图。

例子

y=x^2-10x+15
x=0:1:10;
y=x.^2-10.*x+15;
plot(x, y);
title('Plot of y=x^2-10.*x+15');
xlabel('x');
ylabel('y');
grid on;

输出

MATLAB 2-D绘图

多个地块:

例子

f(x)=sin2x
d/dx f(x)=2cos2x
x=0:pi/100:2*pi;
y1=sin(2*x);
y2=2*cos(2*x);
plot(x, y1, x, y2);
grid on;

输出

MATLAB 2-D绘图

线条颜色, 线条样式, 标记样式和图例

  • 线条颜色:
y
m
c
r
g
b
w
k
  • 标记样式:
.  → point                                                             
o → circle
x → x-mark
+ → plus
*→ star
s → square
d → diamond
v → triangle(left)
^ → triangle(up)
< → triangle(left)
>→ triangle(right)
p → pentagon
h → hexagon
            <none> → no marker
  • 线型:
-  → solid 
-. → dashed dot
-- →dashed
.. → dotted
<none> → no line

标题:

标题(‘title_string’, ‘Font Name’, Helvetica’, ‘Font Size’, 20.’color’, ‘green’, ‘Font Weight’, ‘light / bold / normal’, ‘Font Angle’, ‘Normal /斜体’);

轴:

轴(“位置”, [左, 底, 宽, 高])

例如:要在(0.2, 0.2)处创建轴, 尺寸为图形窗口的一半。

轴(“位置”, [。2 .2 .5 .5]);

MATLAB 2-D绘图

文本:

将文本字符串添加到绘图区域中的指定位置。

text(r, c, ‘string’);

GTEXT:无需指定文本位置。

gtext(‘string’);

在我们单击的位置, 文本将显示在此处。

传说:

图例位置:

top left		top center		top right 
medium left		medium center           medium right 
bottom left		bottom center           bottom right

例子

x = -pi:pi/20:pi;
plot(x, cos(x), '-ro', x, sin(x), '-.b')
h = legend('cos_x', 'sin_x', 2);

输出

MATLAB 2-D绘图

统计图

英尺(x):

例子

M=10L, S=3L, F=2L, T=1L
x= [10       3	    2           1]
pie(x);

输出

MATLAB 2-D绘图

要拉出第三张幻灯片:

例子

x= [10 3 2 1]
 pie(x);
 y= [0 0 1 0]
 pie (x, y);

输出

MATLAB 2-D绘图

拉文本标签:

例子

x= [10 3 2 1]
     pie(x);
     y= [0 0 1 0]
     pie (x, y, {'Machine', 'Software', 'Furniture', 'Transport'});

输出

MATLAB 2-D绘图

条形图

bar(x):绘制条形图。根据时间索引绘制x的值。

bar(t, x):如果我们想自己给t。

例子

x= [10     3       2       1];
bar(x);

输出

MATLAB 2-D绘图

bar(x, ‘stacked’):

Y= [5 1 2
       8 3 7
       9 6 8
       5 5 5
       4 3 2];
 bar(Y, 'stack')

输出

MATLAB 2-D绘图

打印命令:

打印<选项> <文件名>

选项:

  • -deps:创建单色封装的脚本图像。
  • -depsc:它创建彩色的封装后记图像。
  • -djpeg:其联合摄影专家组。
  • -dpng:其可移植的网络图形。

例如:print -djpeg myimg.jpeg


赞(0)
未经允许不得转载:srcmini » MATLAB 2D基本图形绘制

评论 抢沙发

评论前必须登录!