使用matlab绘制用于论文的漂亮图形

如下代码将绘制一幅y=sin(x)的图片,

%adjust default figure properties to improve quality
figure;
set(gcf,...
    'DefaultLineLineWidth',1,'DefaultAxesLineWidth',.5,...
    'DefaultAxesFontName','Helvetica',...
    'DefaultAxesFontSize',20,...
    'DefaultAxesTickLength',[0.02,0.02],... 
    'DefaultAxesXMinorTick','on','DefaultAxesYMinorTick','on');
set(gcf,'DefaultLineMarkerSize',8);
 
% plot your data here
x=0:0.3:2*pi;
y=sin(x);
plot(x,y,'o-','displayname','$y=\sin (x)$');
xlabel('$x$','interpreter','latex');
ylabel('$y$','interpreter','latex');
h=legend('show');
set(h,'interpreter','latex');
title('http://asc.2dark.org');
 
%save your figure and export to eps format
hgsave('example.fig');
print('-depsc','example.eps');

如要绘制坐标轴紧邻的子图,使用默认的subplot是无法实现的,需要手动设置子图坐标的位置。比如要绘制三幅相连的子图,可以

x=0:0.3:2*pi;
 
figure;
h1=subplot(1,3,1);
plot(x,sin(x));
h2=subplot(1,3,2);
plot(x,cos(x));
h3=subplot(1,3,3);
plot(x,sin(x-1));
 
set(h1,'position',[0.1,0.1,0.26,0.8]);
set(h2,'position',[0.36,0.1,0.26,0.8],'yticklabel','');
set(h3,'position',[0.62,0.1,0.26,0.8],'yaxislocation','right');



注意:
linux系统的桌面特效(比如compiz)可能造成matlab绘制的图形中latex字体显示异常(比如字体间距过小,以至相互重叠)。即使关闭了特效问题仍然存在,但完全删除compiz即可解决问题。

补充:似乎不是compiz的问题,完全删除latex-xft-fonts软件包然后注销重新登录即可。还可参考Matlab Central中的讨论

评论

据说 提交者: 快乐中微子
matlab2010b 提交者: 外星人 (未验证)

评论查看选项

选择您喜欢的显示评论的模式,并点击"保存设置"来激活您所做的改变。