您的位置:首页 > 编程语言 > MATLAB

matlab plot 函数绘制二维图

2016-11-15 14:31 591 查看
简单的x-y坐标图

x=[0:2:18];

y=[0, 0.33, 4.13, 6.29, 6.85, 11.19, 13.19, 13.96, 16.33, 18.17];

plot(x, y)

标题、标注和栅格

plot(x, y)

xlabel(‘Time, sec’)

ylabel(‘Distance, ft’)

title(‘example of plot’)

grid on

figure(2)

重新打开一个新的绘图框

绘制多条曲线

x=0:pi/100:2*pi;

y1 = cos(x*4);

plot(x, y1)

y2 = sin(x);

hold on; %hold on 图形保持

plot(x, y2)

hold off %覆盖原有图形

plot(x, y1, x, y2)

Y=[y1; y2];

plot(x, y) %也可以

线条、颜色和标记和风格

x=[0:2:18];

y=[0, 0.33, 4.13, 6.29, 6.85, 11.19, 13.19, 13.96, 16.33, 18.17];

plot(x, y, ‘:ok’) %单引号内线条的类型和颜色

坐标轴定标和图例标注

axis

如果没有熟人参数,就将坐标轴固定在当前配置状态,再次输入axis就会恢复对坐标轴的控制

axis(v)

axis输入一个四维矢量,分别定义了x轴和y轴的最小值和最大值,例如[xmin, xmax, ymin, ymax]

legend(‘string1’, ‘string2’, etc)

添加图例,对不同曲线加以说明

text(x_coordinate, y_coordinate, ‘string’)

再图中不同位置添加文本框,输入参数为文本框的位置和内容

gtext(‘string’) 添加文本框,位置由鼠标操作确定
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: