如何将Matlab直方图保存为矢量图形?

问题描述 投票:3回答:2

保存这样的直方图时:

x = randn(10000,1);
h = histogram(x)

saveas(gcf, 'test','epsc')

生成的postscript包含某种形式的原始位图。当嵌入pdf时,这看起来真的很难看。

如何将直方图保存为矢量图形?

matlab vector-graphics postscript
2个回答
3
投票

你也可以将图形保存为使用矢量图形的pdf。

x = randn(10000,1);
h = histogram(x);

% set proper paper size before generating pdf
set(gcf, 'Units', 'Inches');
pos = get(gcf, 'Position');
set(gcf, 'PaperPositionMode', 'Auto', 'PaperUnits', 'Inches', 'PaperSize', [pos(3), pos(4)]);
print(gcf, 'test.pdf', '-dpdf', '-r0');

免责声明当我在LaTeX文档中嵌入数字时,我会使用这段代码,但我很确定我是从网上某处复制的(可能是SO)。


2
投票

我找到了两种方法:

set(h,'FaceAlpha',1)

删除所有透明效果,matlab可以将其保存为postscript文件。

将文件另存为svg

saveas(gcf, 'test','svg')

并导入到Inkscape(或您选择的其他程序)并从那里导出为eps文件。

© www.soinside.com 2019 - 2024. All rights reserved.