Matlab Tutorials —— "figure & plot"

We always need figure to demonstrate the data we have.

Here gives an example of the basic way to use figure and plot:


% Start
x = -100:0.1:100;
y1 = x + 1;
y2 = x .* x;

figure(1); % create a new figure 1
plot(x, y1); % plot two curves in one figure
hold on; % To keep current curve appear
plot(x, y2);
% you can actually use the following one, it works the same
% plot(x,y1,  x,y2);
legend('y1', 'y2'); % add lengeds
title('Plot Demonstration'); % title of the plot
xlabel('x'); ylabel('y') % label of axis
axis([-5 5 -10 10]); % scale of axes [xmin xmax ymin ymax]
set(gca, 'XTick', (-5: 1: 5)); % set the step of axes [min: step: max]
set(gca, 'YTick', (-10: 2: 10)); 
grid on; % plot with grid on



% Other constructing method
x = 1:5:100;
Two = 3 * x - 2;

figure('Name', 'Two', 'NumberTitle', 'off'); % create a new figure named 'Two' without number title
plot(x, Two, ... % some parameters to change a curve's properties
    ':', ...
    'Color', 'b', ...
    'LineWidth', 1, ...
    'Marker', '*', ...
    'MarkerFaceColor', [1, 0.1, 0.1], ...
    'MarkerEdgeColor', [1, 0.1, 0.1], ...
    'MarkerSize', 3 ...  
    );  



% To use subplot to have multiple plots in one figure
k = linspace(0, 9.42, 100); % k is a vector including 100 numbers from 0 to 3pi
z0 = sin(k);
z1 = cos(k);

figure('Name', 'Subplot');
subplot(2,2, 1); % a subplot constructed as 2 by 2 matrix and we use the first one
plot(k, z0);
subplot(2,2, 2); % same as before but using the second one this time
plot(k, z1);
subplot(2,2, [3,4]); % using 3 and 4 together to plot the last one
plot(k, z0 + z1);


Appendix may be needed:

MarkerDescription
oCircle
+Plus sign
*Asterisk
.Point
xCross
sSquare
dDiamond
^Upward-pointing triangle
vDownward-pointing triangle
>Right-pointing triangle
<Left-pointing triangle
pPentagram
hHexagram
ColorDescription

y

yellow

m

magenta

c

cyan

r

red

g

green

b

blue

w

white

k

black
Line StyleDescription
-Solid line (default)
--Dashed line
:Dotted line
-.Dash-dot line

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值