可结合柱状图画法,丰富画图经验,柱状图参照:https://blog.csdn.net/wmz13248/article/details/106384341

第1步:

text(x,y,num2str(z)); %在坐标(x,y)处,添加数值z,z需要转换成字符串形式

set(gca,‘XTickLabel’,{number1});
% set 设置操作
% 向图中添加横坐标数值,横坐标不再是 1,2,3…

%gca,表示图中的线,XTickLabel表示选择的是图中的横轴(线)坐标值,number1为需要把横轴修改成的值

legend(‘曲线1’,‘曲线2’); %右上角标注曲线示例

number1=[ 700  1076  947  660  595  1194  265 465  250 830  227 ];  %横轴坐标值
pixel1=[45315,32302,31932,18221,14155,13232,9431,7217,3928,3166,2476]; 	 %折线上显示的数值
time1=[9.64  9.81  7.46 5.75 3.80  4.67  3.65  3.16  2.26  2.75 1.99 ];  %纵轴坐标值
time2=。。。。。。   %随便写了,数值是多少不重要了

plot(time1,‘o-r’); %红色,实线
hold on %保持住,红线别被蓝线覆盖了
plot(time2,‘o–b’); %蓝色,虚线

for i=1:length(time1)
text(i,time1(i),num2str(pixel1(i))); %向图中添加描述值,只写一个,time2的同理,不写了
end

set(gca,‘XTickLabel’,{ number1}); %向图中添加横坐标数值

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

运行图:
在这里插入图片描述

第2步:

上图的字体太小,放大

plot(time1,'o-r', 'LineWidth',3);		% 线宽,设置为3
hold on
plot(time2,'o--b', 'LineWidth',3);

for i=1:length(time1)
text(i,time1(i),num2str(pixel1(i)),‘FontSize’,20); % 折线上的字号,设置为20
end
for i=1:length(time2)
text(i,time2(i),num2str(pixel2(i)),‘FontSize’,20);
end

xlabel(‘帧序号’,‘Fontname’, ‘Times New Roman’,‘FontSize’,20); % 横轴:字体设置为Times New Roman,字号设置为20
ylabel(‘时间/单位:秒’,‘Fontname’, ‘Times New Roman’,‘FontSize’,20); % 同上
title(‘对比图’,‘Fontname’, ‘Times New Roman’,‘FontSize’,20); % 同上
set(gca,‘XTickLabel’,{ number1}); %添加横轴数值,不再是1,2,3..... % 和上一段程序相同
grid on %添加网格
legend(‘曲线1’,‘曲线2’); %右上角添加示例
set(gca,‘linewidth’,1,‘fontsize’,20,‘fontname’,‘Times’); %设置示例的线宽为1,字号为20,字体为Times

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

运行图:
在这里插入图片描述
第3步

折线挡住了字体,可以调整字体相对于折线的高度,向上移用加号 +,向下移用减号 -

for i=1:length(time1)
    text(i,time1(i)+1,num2str(pixel1(i)),'FontSize',20);  % 红色折线的数字向上移 用加号 +
end
for i=1:length(time2)
    text(i,time2(i)-1,num2str(pixel2(i)),'FontSize',20);  % 蓝色折线的数字向上移 用加号 -
end

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

运行图
在这里插入图片描述

Logo

鸿蒙生态一站式服务平台。

更多推荐