[MatLab] Image plotting

1. Draw a two-dimensional image

        1. Draw a line on a graph

                The drawing code is as follows:

x = 0:0.01:2*pi;
y = sin(x);
figure              %建立幕布
plot(x,y)           %绘制图像
%设置图像属性
title('y=sin(x)')
xlabel('x')
ylabel('y')

xlim([0 2*pi])      %限制x轴的值域

                 Customize the color of the graph line; the optional colors are shown in the table below

red r pink m
green g green c
blue b white w
yellow y black k

                Customize the line shape of the graph (repeat the sample graph)

solid line -
dotted line --
colon line :
dotted line -.

                        Data Point Options Parameters

         2. Draw multiple lines on one graph

                ① Draw lines on both sides

                        The graph lines occupy the y-axis of one side respectively, and use yyaxis to select the side to which the image belongs, but it cannot be repeated

x = 0:0.01:20;
y1 = sin(x)
y2 = cos(x)

figure
yyaxis left
plot(x,y1)
yyaxis right
plot(x,y2)

                 ② Draw the same side graph line

                        At the beginning, yyaixs is also required to specify the y-axis, but it is not necessary to specify it later, and it is changed to hold on to keep the graph line.

clear all
x = 0:0.01:20;
y1 = sin(x)
y2 = cos(x)

figure
yyaxis left
plot(x,y1)
hold on
plot(x,y2)

 2. Draw a 3D image

t = 0:pi/50:10*pi
plot3(sin(t),cos(t),t)
xlabel('sin(t)')
ylabel('cos(t)')
zlabel('t')
grid on        %展开网格线
axis square    %将图像变为正方形(如因尺度造成图片变形可以使用)

Guess you like

Origin blog.csdn.net/weixin_37878740/article/details/129294022