1.
Matlab自带绘图函数,坐标轴不带箭头,如下所示:
2.
使用系统函数绘图,在生成的图形上叠加两个annotation对象表示x轴和y轴,定义对象位置和样式使其显示为带箭头坐标轴的样子。
3.
函数名称 | 函数功能 | 备注 |
plot_with_arrow | 绘图主函数 | 调用格式见函数头 |
plot_with_arrow_Test | plot_with_arrow的测试程序 | 测试请运行此文件 |
Arrow_Title | 设置箭头坐标轴图形的标题 | 与系统函数title类似 |
Arrow_XY | 确定坐标轴箭头的起始位置 | |
Arrow_Xlabel | 设置箭头坐标轴图形的x轴标签 | 与系统函数xlabel类似 |
Arrow_Ylabel | 设置箭头坐标轴图形的y轴标签 | 与系统函数ylabel类似 |
stem_self | 自定义stem函数,去除stem函数中的0位线,不适合大数据量绘图 | 用于测试程序中 |
isaxes | 判断对象是否为坐标轴(axes)对象 | |
isfigure | 判断对象是否为图形(figure)对象 | |
ischild | 判断对象是否为另一对象的子对象 | |
函数m文件及测试文件下载地址:
http://ishare.iask.sina.com.cn/f/66484659.html
4.
测试1:带箭头属性绘图
clc
clear
x
y
Attribute_Set = {'LineWidth',1.5};
[h h_a h_p h_arrow] = plot_with_arrow( [],x,y,'k',[],[],Attribute_Set);
htext_x = Arrow_Xlabel([],'时间/s',[]);
htext_y = Arrow_Ylabel([],'幅值/V',[]);
htext_title = Arrow_Title([],'图形Test');
测试2:用数值指示箭头坐标轴位置
clc
clear
x
y
figure
ha1 =subplot(211);
pos = [0.10.7 1 1 0.1 0.7];
[h h_a h_ph_arrow] = plot_with_arrow( ha1,x,y,'k',pos);
htext_x =Arrow_Xlabel([],'时间/s',pos);
htext_y =Arrow_Ylabel([],'幅值/V',pos);
htext_title= Arrow_Title([],'图形Test');
ha2 =subplot(212);
pos = [0.80.2 0.1 0.6 0.8 0.2];
[h h_a h_ph_arrow] = plot_with_arrow( ha2,x,y,'k',pos);
htext_x =Arrow_Xlabel([],'时间/s',pos);
htext_y =Arrow_Ylabel([],'幅值/V',pos);
htext_title= Arrow_Title([],'图形Test');
测试3:用数值指示箭头坐标轴位置
clc
clear
x
y
h_f =figure;
[h h_a h_p]= plot_with_arrow( h_f,x,y,'k');
htext_x =Arrow_Xlabel([],'时间/s',[]);
htext_y =Arrow_Ylabel([],'幅值/V',[]);
htext_title= Arrow_Title([],'图形Test');
测试4:输入坐标轴句柄
clc
clear
x
y
figure
h_a =subplot(211);
[h h_a h_p]= plot_with_arrow( h_a,x,y,'k');
htext_x =Arrow_Xlabel([],'时间/s',[]);
htext_y =Arrow_Ylabel([],'幅值/V',[]);
htext_title= Arrow_Title([],'图形Test1');
h_a2 =subplot(212);
[h h_a h_p]= plot_with_arrow( h_a2,x,y,'k','nn');
htext_x =Arrow_Xlabel([],'时间/s','nn');
htext_y =Arrow_Ylabel([],'幅值/V','nn');
htext_title= Arrow_Title([],'图形Test2');
测试5:其它绘图函数
clc
clear
x =-2.9:0.2:2.9;
y =exp(-x.*x);
figure
h_a =subplot(211);
[h h_a h_ph_arrow] = plot_with_arrow( h_a,x,y,'r',[],@bar);
htext_x =Arrow_Xlabel([],'时间/s',[]);
htext_y =Arrow_Ylabel([],'幅值/V',[]);
htext_title= Arrow_Title([],'图形Test1');
h_a2 =subplot(212);
[h h_a h_ph_arrow] = plot_with_arrow( h_a2,x,y,'b',[],@stem);
htext_x =Arrow_Xlabel([],'时间/s',[]);
htext_y =Arrow_Ylabel([],'幅值/V',[]);
htext_title= Arrow_Title([],'图形Test2');
测试6:绘制光坐标轴,holdon之后再绘制图形
pos= 'an';
[h ha hph_arrow]
holdon
t =linspace(0,4*pi,200);
x =sin(t);
plot(t,x)
htext_x =Arrow_Xlabel([],'时间/s',pos);
htext_y =Arrow_Ylabel([],'幅值/V',pos);
htext_title= Arrow_Title([],'图形Test');
测试7:综合绘制
clc
clear
x
y
figure
h_a1 =subplot(221);
[h1 h_a1h_p1 h_arrow1] = plot_with_arrow( h_a1,x,y,'r');
htext_x1 =Arrow_Xlabel([],'时间/s',[]);
htext_y1 =Arrow_Ylabel([],'幅值/V',[]);
h_a2 =subplot(222);
pos2= 'an';
[h2 h_a2h_p2 h_arrow2] = plot_with_arrow( h_a2,x,y,'r',pos2);
htext_x2 =Arrow_Xlabel([],'时间/s',pos2);
htext_y2 =Arrow_Ylabel([],'幅值/V',pos2);
h_a3 =subplot(223);
pos3= 'nn';
[h3 h_a3h_p3 h_arrow3] = plot_with_arrow( h_a3,x,y,'r',pos3);
htext_x3 =Arrow_Xlabel([],'时间/s',pos3);
htext_y3 =Arrow_Ylabel([],'幅值/V',pos3);
h_a4 =subplot(224);
pos4= 'np';
[h4 h_a4h_p4 h_arrow4] = plot_with_arrow( h_a4,x,y,'r',pos4);
htext_x4 =Arrow_Xlabel([],'时间/s',pos4);
htext_y4 =Arrow_Ylabel([],'幅值/V',pos4);
测试8:坐标调整
当坐标轴中的子对象(如曲线等)被Label对象挡住时,可通过axis或xlim、ylim调整坐标轴位置来消除这种影响也可通过h_text_x/y句柄或是通过鼠标手动调整Label对象的位置
clc
clear
x
y
figure
h_a1 =subplot(221);
[h1 h_a1h_p1 h_arrow1] = plot_with_arrow( h_a1,x,y,'r','pa');
htext_x1 =Arrow_Xlabel([],'时间/s','pa');
htext_y1 =Arrow_Ylabel([],'幅值/V','pa');
htext_title1 =Arrow_Title(h_a1,'调整前');
h_a2 =subplot(222);
[h2 h_a2h_p2 h_arrow2] = plot_with_arrow( h_a2,x,y,'b','pa');
htext_x2 =Arrow_Xlabel([],'时间/s','pa');
htext_y2 =Arrow_Ylabel([],'幅值/V','pa');
htext_title2 =Arrow_Title(h_a2,'调整后');
axes(h_a2)
axis([0 12-1.5 1.5])
h_a3 =subplot(223);
pos3= 'nn';
[h3 h_a3h_p3 h_arrow3] = plot_with_arrow( h_a3,x,y,'r',pos3);
htext_x3 =Arrow_Xlabel([],'时间/s',pos3);
htext_y3 =Arrow_Ylabel([],'幅值/V',pos3);
htext_title3 =Arrow_Title(h_a3,'调整前');
h_a4 =subplot(224);
[h4 h_a4h_p4 h_arrow4] = plot_with_arrow( h_a4,x,y,'b',pos3);
htext_x4 =Arrow_Xlabel([],'时间/s',pos3);
htext_y4 =Arrow_Ylabel([],'幅值/V',pos3);
htext_title4 =Arrow_Title(h_a4,'调整后');
axes(h_a4)
axis([-2 10-1.5 1])
测试9:修改箭头属性
x
y
h_f =figure;
[h h_a h_ph_arrow] = plot_with_arrow( h_f,x,y,'k');
htext_x =Arrow_Xlabel([],'时间/s',[]);
htext_y =Arrow_Ylabel([],'幅值/V',[]);
%改变颜色
set(h_arrow,'color','r')
%修改箭头类型
set(h_arrow,'HeadStyle','vback3')
5.
有Matlab/Simulink方面的技术问题,欢迎发送邮件至944077462@qq.com讨论。
联系客服