获取屏幕单元matlab以保存为pdf

时间:2013-04-08 11:09:56

标签: matlab

我想将此图片导出为pdf格式:

enter image description here

P2_tilde =

0.1029    0.4118    0.0245    0.1814    0.2794
0.3925    0.0234    0.0280    0.4626    0.0935
0.0928    0.1237    0.2680    0.2990    0.2165
0.0699    0.2219    0.0182    0.5106    0.1793
0.2611    0.0887    0.0837    0.3251    0.2414

figure('color',[1,1,1])

hBar2=bar3(P2_tilde);
colormap('pink')

set(hBar2,{'CData'},C);   
set(gca,'xticklabel',surfaces)
set(gca,'yticklabel',surfaces)
surfaces={'Equipment','Patient','Hygiene products','Near-bed','Far-bed'};
colorbar
zlabel('Probability');

colormap('pink')
colorbar('location','southOutside')
set(gca,'xticklabel',surfaces)
set(gca,'yticklabel',surfaces)
surfaces={'Equipment','Patient','Hygiene products','Near-bed','Far-bed'};
zlabel('Probability');

想要导出为PDF格式:

currentScreenUnits=get(gcf,'Units')     % Get current screen units
currentPaperUnits=get(gcf,'PaperUnits') % Get current paper units
set(gcf,'Units',currentPaperUnits)      % Set screen units to paper units
plotPosition=get(gcf,'Position')        % Get the figure position and size
set(gcf,'PaperSize',plotPosition(3:4))  % Set the paper size to the figure size
set(gcf,'Units',currentScreenUnits)     % Restore the screen units

print -dpdf ptilde      % PDF called "ptilde.pdf"

完全不在页面上。有什么想法如何将图形居中在画布上,并使其只是图形的大小?否则我怎么修剪它?

2 个答案:

答案 0 :(得分:2)

我无法完全复制你的数字(代码中的错误:需要C的定义)但是使用

f=figure('color',[1,1,1]);
%rest of figure code....
set(f,'PaperPositionMode','auto')
print -dpdf ptilde

另外,我不确定如何从MATLAB中裁剪pdf,但如果你想要一个裁剪的矢量图形,请使用-depsc或-depsc2作为打印标志。请参阅MATLAB帮助打印。

答案 1 :(得分:2)

PaperSizer参数需要是要打印的纸张的实际尺寸(将显示的pdf文件),而不是Matlab图形在屏幕上显示的尺寸。例如,如果您将其更改为:

set(gcf,'PaperSize',[9,11])  

你会得到一些看似合理的东西。