Matlab学术绘图
源码
保存格式:
.emf:word中使用emf格式.eps:Latex中使用eps格式svg:有色块是,使用svg格式更清晰
%% Matlab 基础绘图
% Author : Xu Zhe
% Date : 2021-06-29
% Brief :
%% 系统初始化
close all
clear
clc
%% 数据
x = linspace(-pi,2*pi,100);
y1 = sin(x);
y2 = cos(x);
%% 绘图
% 绘图全局参数
Wfig = 8; % 一般论文用图宽度,8cm
Hfig = 5.5;
fontsize = 9;
fontEN = 'Times New Roman';
fontCN = '宋体';
% 配置窗口
figure('name','Matlab绘图格式化','color','w');
set(gcf,'unit','centimeters','position',[0,15,Wfig,Hfig]);
% 绘图内容
plot(x,y1,'b-','linewidth',1.0);
grid on
hold on
plot(x,y2,'r--','linewidth',1.0);
% 设置坐标轴
set(gca,'FontName',fontEN,'FontSize',fontsize); % 设置坐标轴字体
set(gca,'XTick',-pi:pi/2:2*pi); % 设置坐标轴刻度
set(gca,'linewidth',1);
set(gca,'XTicklabel',{'-π','-π/2','0','π/2','π','3π/2','2π'});
set(gca,'Xlim',[-pi,2*pi]);
xlabel('\fontname{宋体}坐标\fontname{Times New Roman}X','FontSize',fontsize);
ylabel('Y','FontName',fontEN,'FontSize',fontsize);
% 去除页边空白(可以不加)
% ax = gca;
% outerpos = ax.OuterPosition;
% ti = ax.TightInset;
% left = outerpos(1) + ti(1);
% bottom = outerpos(2) + ti(2);
% ax_width = outerpos(3) - ti(1) - ti(3);
% ax_height = outerpos(4) - ti(2) - ti(4);
% ax.Position = [left bottom ax_width ax_height];
% 图例
legend('$\sin(x)$','$\cos(x)$','location','northeast','Interpreter','LaTex','FontSize',fontsize,'FontName','Times New Roman');
