MATLAB二维绘图总结

hold on;    %图像保持打开

hold off;    %图像保持关闭,默认关闭

axis on;     %坐标打开,默认打开

axis off;     %坐标关闭

grid on;     %显示格点

grid off;     %隐藏格点,默认隐藏

pause;      %暂停,单击鼠标继续

 

% 1

% 单纵坐标画图,格式红色、实线

clear

clc

figure

Vcs = 0.2;                 %参考电压

k = 1;                    %电流/电压比例系数

x = linspace(0,2*pi,50);      %线性取值区间

Y1 = sin(x);                %电压

Y2 = k*sin(x);              %电流

figure                    %新建幕布

hold on

plot(x,Y2,'r-');              %单纵坐标画图,格式红色、实线

xlim([-4,4]);               %X轴范围定义-2π~2π

xlabel('x');

ylabel('y=sin(x)');           %Y1轴名字设置"y=sin(t)"

title('功率曲线');           %图像名定义"功率曲线"

gtext('正弦曲线');          %幕布输出字符串"正弦曲线"

 

% 2

% 多维子图,格式默认

 

clear;

clc;

figure

xlabel('x');

t = -4:0.001:4;

ut1 = stepfun(t,-2);      %阶跃函数,-2跳变

ut2 = stepfun(t,2);       %阶跃函数,2跳变

gt = ut1 - ut2;           %gt函数定义句柄

figure                     %新建幕布

subplot(3,1,1);          %31列第1个图像

plot(t,ut1);             %调用句柄ut1,画图

ylabel('y1');

axis([-4,4,-0.5,1.5]);      %x轴和y轴范围定义

 

subplot(3,1,2);          %31列第2个图像

plot(t,ut2);             %调用句柄ut2,画图

ylabel('y2');

axis([-4,4,-0.5,1.5]);      %x轴和y轴范围定义

 

subplot(3,1,3);          %31列第3个图像

plot(t,gt);              %调用句柄gt,画图

ylabel('y3');

axis([-4,4,-0.5,1.5]);      %x轴和y轴范围定义

 

% 3

% 双纵坐标画图

clear;

clc;

figure                                  %新建幕布

x = linspace(0,2*pi,50);                    %线性取值区间

Y1 = sin(x);                              %电压

Y2 = cos(x);                              %电流

[AX,H1,H2] = plotyy(x,Y1,x,Y2,'plot');          %双纵坐标画图,AX坐标轴,H图像

xlabel('弧度');                            %X轴名字设置"弧度"

set(get(AX(1),'Ylabel'),'String','Y1=sin(x)');      %左纵坐标名设置"Y1=sin(x)"

set(get(AX(2),'Ylabel'),'String','Y2=cos(x)');      %左纵坐标名设置"Y2=cos(x)"

set(AX(1),'ycolor','r');                       %坐标轴和符号颜色设置,红色

set(AX(2),'ycolor','g');                       %坐标轴和符号颜色设置,绿色

title('输入功率');                          %图像名定义"输入功率"

set(H1,'Color','r','LineStyle','-');               %设置曲线各属性值,红色实线

set(H2,'Color','g','LineStyle','--');              %设置曲线各属性值,绿色虚线

axis([AX(1),AX(2)],[-pi/10,2*pi+pi/10,-1.1,1.1]);  %坐标限值,必要时加上

legend('one','two');                        %增加图例

 

% 4

% 常规饼图

x = [5 10 7 1.3];                                %区域大小值

label = {'Banana', 'Pear','Orange','Raspberry'};        %区域名定义

pie(x,label);                                   %绘制常规饼图

 

% 5

% 立体饼图

x = [5 10 7 1.3];                                 %区域大小值

label = {'Banana', 'Pear','Orange','Raspberry'};         %区域名定义

pie3(x,label);                                   %绘制立体饼图

 

% 6

% 极坐标图

t = 0:pi/50:2*pi;               %极坐标角度

r = sin(t).*cos(t);               %角度对应数值

polar(t,r,'r-+');                 %绘制极坐标图

posted @ 2021-03-11 23:24  JYLG  阅读(108)  评论(0)    收藏  举报