1、前记:上接MATLAB基础--数据出图中的内容介绍figure出数据图时一些细致的设置。
主要包括线型设置,坐标区设置,legend设置
function[]=plot_en()
disp('------------------------------------------------------------------');
disp('Plots the Energy balance');
load envar.dat;
load timevar.dat;
EN=envar;T=timevar;
set(0,'DefaultLineLineWidth',1.5)%默认线条粗细
fh1=figure('Name','Energy Balance','NumberTitle','off');%取消figur图编号
subplot(2,1,1)%窗口划分为两行一列,第一个
set(fh1, 'color', 'white'); % figur背景设为白色
plot(T,EN(:,1),'-r',T,EN(:,4),'-.m');%plot数据
set (gca,'fontsize',10,'fontweight','n','fontname','times new romans','linewidth',0.5,'Box', 'off','TickDir','out' );
% 刻度字体大小 刻度线条粗细
% 图框闭合成Box-on,off 不闭合 刻度线向里-in,out向外
%title(' ENERGY BALANCE OF SIMULATION THROUGH LSIM ','FontSize',8); %标题名
xlabel('time (s)','FontSize',10); %X轴单位,字体大小
ylabel('Energy (J)','FontSize',10); %Y轴单位,字体大小
h=legend('Potential','Total'); %线型标识名
set(h,'Orientation','horizontal','Color', 'c','Box', 'on','Location','best','fontsize',10,'fontweight','n','fontname','times new romans','linewidth',2.5)
% 对线型标识名legend的设置---蓝绿色C背景box包围打开-on,关闭-off ;位置自动最佳;legend字体大小10;box线框粗细2.5
% plot常用颜色,r 红,g 绿,b 蓝,c 蓝绿,m 紫红,y 黄,k 黑,w 白;color阈值[1 0 0]--代表红色
subplot(2,1,2)%%窗口划分为两行一列,第2个
set(fh1, 'color', 'white'); % sets the color to white
plot(T,EN(:,2),T,EN(:,3));
set (gca,'fontsize',10,'fontweight','n','fontname','times new romans','linewidth',0.5,'Box', 'on','TickDir','in' );
% title(' ENERGY BALANCE OF SIMULATION THROUGH LSIM ','FontSize',8);
xlabel('time (s)','FontSize',10);
ylabel('Energy (J)','FontSize',10);
h=legend('Kinetic','Actuator');
set(h,'Orientation','horizontal','Color', 'none','Box', 'off','Location','best','fontsize',10,'fontweight','n','fontname','times new romans','linewidth',0.5)
% legend位置northoutside,外-北;'north' | 'south' | 'east' | 'west' |'northeast' | 'northwest' | 'southeast' | 'southwest' | 'northoutside' |
%'bestoutside'|'northeast' | 'northwest' | 'southeast' | 'southwest' | 'northeastoutside' |
%'northwestoutside' | 'southeastoutside' | 'southwestoutside'
结果显示:
2、figure数据出图时,通过导出设置或插入功能也可以丰富,如在figure中添加方框、坐标区、添加注释等。如下简单操作以示....
3、有时候想查看某一个插入功能的代码时,可以右键选中后点击显示代码,在有时候可以更加生成的代码重构数据出图的代码。