【问题标题】:Matlab print -dpdf produces fuzzy linesMatlab print -dpdf 产生模糊线条
【发布时间】: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


【解决方案1】:

根据this answer,这是一个已确认的错误,并且回答者提供了一个功能来纠正 EPS 文件的问题。

由于您要创建 PDF,我建议使用 export_fig(需要 Ghostscript install),在下面的测试脚本中,它会在生成的 PDF 中创建一条平滑线。

clc();
clear();

figure(1);

% Get states
n  = 800;
x = linspace(0,2*pi,n);
s = [x.*cos(x);x.*sin(x)] + 0.3*exp(-0.3*[x;x]).*(rand(2,n)-0.5) ;

% Draw trajectory
plot(s(1,:), s(2,:), 'linewidth', 1);
axis([-20,20,-20,20]);
daspect([1,1,1])

% Print to PDF
print('traj.pdf','-dpdf', '-r600');
export_fig('traj2.pdf','-dpdf','-r600');

printPDF 输出:

export_figPDF 输出:

【讨论】:

  • 非常感谢,我马上试试!
  • 我可以确认export_fig 就像一个魅力。非常感谢您的努力!
猜你喜欢
  • 1970-01-01
  • 2012-05-25
  • 1970-01-01
  • 2019-11-06
  • 1970-01-01
  • 2014-04-20
  • 1970-01-01
  • 1970-01-01
  • 2019-04-13
相关资源
最近更新 更多