【发布时间】:2015-07-01 16:59:30
【问题描述】:
在 matlab 中将二维图打印为 pdf 时遇到问题。我正在尝试将以下图打印到文件中(pdf、eps、svg,没关系):
问题在于,在某些时候,这条线非常“摇摆不定”(抱歉没有更好的词)。我放大了上部,所以你可以明白我的意思:
这显然不是matlab图形窗口的问题。但是当我将它打印成 pdf 时,它是这样的:
pdf、svg 和 eps 的结果相同。我想问题是 matlab 正在创建一个矢量化路径(这很好!)但是路径线太粗,然后可以看到每个小尖峰。
这是我用来生成 pdf 的代码:
sTitle = 'trajectory';
sFile = 'Data/trajectory.mat';
sPdfFile = 'pdfs/trajectory.pdf';
linewidth = 1;
fontsize1 = 18;
fig = figure;
% Adjust figure window size
set(fig, 'Position', [100 100 1400 800]);
% Set title
title(sTitle);
% Get states
[s, t] = load_data(some_data);
% Draw trajectory
plot(s(1,:), s(2,:), 'linewidth', linewidth);
% Labels and stuff
xlabel('x^W [m]', 'fontsize', fontsize1);
ylabel('y^W [m]', 'fontsize', fontsize1);
set(gca, 'fontsize', fontsize1)
% Axis font
set( gca , ...
'FontName' , 'Helvetica' );
set(gca, ...
'Box' , 'on' , ...
'TickDir' , 'out' , ...
'TickLength' , [.02 .02] , ...
'XMinorTick' , 'on' , ...
'XGrid' , 'on' , ...
'XMinorGrid' , 'off' , ...
'YMinorTick' , 'on' , ...
'YGrid' , 'on' , ...
'XColor' , [.3 .3 .3], ...
'YColor' , [.3 .3 .3], ...
'XTick' , -5:1:5, ...
'XTickLabelMode', 'auto', ...
'YTick' , -5:1:5, ...
'LineWidth' , 1 );
% Adjust view
axis([-2.5 2.5, -2.7 0.5]);
% Correct data aspect ratio
daspect([1,1,1])
% Print to PDF
width = 10;
height = 5;
set(gcf, 'PaperPosition', [0 0 width height]); %Position plot at left hand corner with width 5 and height 5.
set(gcf, 'PaperSize', [width height]); %Set the paper to have width 5 and height 5.
print('-dpdf', '-r600', sPdfFile);
【问题讨论】:
-
[s, t] = load_data(some_data);行使您的代码无法运行。您能否提供一个最低限度的工作示例? -
@LuisMendo 是的,我知道,但我无法提供一个简单的示例来创建这种混乱的数据。
标签: matlab pdf printing plot eps