altmany / export_fig

A MATLAB toolbox for exporting publication quality figures
BSD 3-Clause "New" or "Revised" License
1.27k stars 365 forks source link

Export_fig cannot output pictures in PDF and EPS format #356

Closed tiange1949 closed 2 years ago

tiange1949 commented 2 years ago

export_fig Version: 3.26 GhostScript Version: 9.56.1 for Windows (64 bit)

Error Code:

hostscript error: configurationerror in --setpagedevice--
 * perhaps C:\Users\dai19\AppData\Local\Temp\tp3f178042_9e5f_4a15_ba5a_a0f44d596621.pdf is open by another application
 * or maybe you have another gs executable in your system's path

Ghostscript path: gswin64c.exe
Ghostscript options: -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile="C:\Users\dai19\AppData\Local\Temp\tp3f178042_9e5f_4a15_ba5a_a0f44d596621.pdf" -dEPSCrop -sFONTPATH="C:\Windows\Fonts" -f "C:\Users\dai19\AppData\Local\Temp\tp4ea4e3a0_9a59_498f_90c7_a9154ce2fcd7.eps"

Please ensure:
 * that the function you used (C:\Users\dai19\OneDrive\04-Programming\08-MATLAB\Useful Addons\export_fig-master\export_fig.m) version 3.26 is from the expected location
 * and that you did not made a mistake in export_fig's expected input arguments
 * and that ghostscript is properly installed in gswin64c.exe

If the problem persists, then please report a new issue.
In your report, please upload the problematic EPS file: C:\Users\dai19\AppData\Local\Temp\tp4ea4e3a0_9a59_498f_90c7_a9154ce2fcd7.eps (you can then delete this file).

错误使用 eps2pdf (第 258 行)
Error: /configurationerror in --setpagedevice--
Additional information: [/PageSize [671 -26]]
Operand stack:
   --nostringval--   (%%BoundingBox: 24 498 695 472)   --dict:1/2(ro)(G)--   --nostringval--
   --nostringval--   (%%BoundingBox: 24 498 695 472)   1   24   498   false   --dict:1/1(L)--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   0Policy   --nostringval--   2   %stopped_push
   --nostringval--   0Policy   0Policy   false   1   %stopped_push   1990   1   3
   %oparray_pop   1989   1   3   %oparray_pop   1988   1   3   %oparray_pop   0Policy   1977
   1   3   %oparray_pop   1833   1   3   %oparray_pop   --nostringval--   %errorexec_pop
   .runexec2   --nostringval--   0Policy   --nostringval--   2   %stopped_push
   --nostringval--   %ztokenexec_continue   (scanner state)   0Policy   0Policy   0Policy
   0Policy   1986   8   3   %oparray_pop   0Policy   1984   11   3   %oparray_pop   0Policy
   1938   10   3   %oparray_pop   0Policy   1937   16   3   %oparray_pop   0Policy
   --dict:1/10(L)--   0Policy   6   %dict_continue   1934   19   3   %oparray_pop
Dictionary stack:
   --dict:768/1123(ro)(G)--   --dict:0/20(G)--   --dict:79/200(L)--
Current allocation mode is local
Current file position is 313
GPL Ghostscript 9.56.1: Unrecoverable error, exit code 1

出错 export_fig (第 1027 行)
                eps2pdf(tmp_nam, pdf_nam_tmp, 1, options.append, options.colourspace==2,
                options.quality, options.gs_options);

出错 fig__202205101554 (第 304 行)
export_fig 'C:\Users\dai19\Desktop\test41' '-pdf' -r600

Matlab Origin Code

clear;clc;
Xpump = [74.7000000000000   111.300000000000    149.200000000000    188.600000000000    226.800000000000    265.700000000000    306 345];
Yout = [12.1820600000000    26.7744800000000    35.4557600000000    40.8271500000000    44.9735400000000    49.1908200000000    51.9281000000000    54.2608700000000];
Yeffi = [9.10000000000000   29.8000000000000    52.9000000000000    77  102 130.700000000000    158.900000000000    187.200000000000];

figure;
f=gcf;
% ------------------------------------------------------
% 图窗外观
f.MenuBar='figure';     % 菜单栏显示方式('figure'|'none')
f.ToolBar='auto';       % 工具栏显示方式('auto'|'figure'|'none')
f.DockControls='on';    % 交互式图窗停靠('on'|'off')
f.Color=[255 255 255]/255;      % 背景色(RGB三元组 | 十六进制颜色代码 | 颜色短名称'r')
f.WindowStyle='normal'; % 窗口样式('normal'|'modal'|'docked')
f.WindowState='normal'; % 窗口状态('normal'|'minimized'|'maximized'|'fullscreen')

% -------------------------------------------------------------------------
% 位置和大小
a=[8 2 25 20];
f.Units='centimeters';  % 测量单位
f.Position=a;        % 可绘制区域的位置和大小
f.InnerPosition=a;   % 与Position属性等同
f.OuterPosition=a;   % 外部边界的位置和大小
f.Resize='on';       % 可调整大小的图窗

% 绘图
% -------------------------------------------------------------------------
f.Colormap=[1 0 1;0 0 1;1 1 0]; % 图窗坐标区内容的颜色图,影响surface、image和patch函数
f.Alphamap=linspace(0,1,64);    % Axes内容的透明度映射
f.NextPlot='add';   % 有关添加下一绘图的指令
f.Renderer='opengl';    % 选择渲染器
f.GraphicsSmoothing='on';   % 坐标区图形平滑处理

% 打印和导出
% -------------------------------------------------------------------------
f.PaperUnits='centimeters'; % 用于PaperSize和PaperPosition的单位
f.PaperPositionMode='manual';   % 打印或保存时使用显示的图窗大小的指令
b=a/2*2;
f.PaperPosition=[0 0 b(3) b(4)];    % 保存页面时的图窗大小和位置
f.PaperType='<custom>'; % 自定义页面类型
f.PaperSize=[b(3) b(4)];    % 自定义页面大小
f.PaperOrientation='portrait';  % 页面方向
f.InvertHardcopy='on'; % 保存时的图窗背景色 on-白色,off-与当前颜色一致

% 标识符
% -------------------------------------------------------------------------
f.Name='Output versus Pump power';

% 开始绘图
p1 = plot(Xpump,Yout);
xlabel('Pump power (W)','FontSize',18,'FontWeight','bold');
ylabel('Output power (W)','FontSize',18,'FontWeight','bold');

% 线条颜色和样式
p1.Color=[0  51 186]/255;
p1.LineStyle='-';
p1.LineWidth=3;
p1.LineJoin='round';
% 标记
p1.Marker='o';
p1.MarkerIndices=1:length(Yout);
p1.MarkerSize=8;
p1.MarkerEdgeColor=[0  51 186]/255;
p1.MarkerFaceColor=[0  51 186]/255;

ax=gca;
% 坐标轴字体
% -------------------------------------------------------------------------
ax.FontName='Arial';    % 'Helvetica'
ax.FontWeight='bold';
ax.FontSizeMode='auto';
ax.FontSize=20;
ax.FontAngle='normal';
ax.LabelFontSizeMultiplier=1.1;
ax.TitleFontSizeMultiplier=1.1;
ax.FontUnits='points';
ax.FontSmoothing='on';
ax.Color=[1 1 1];
ax.LineWidth=2;
ax.Box='on';

% 标签
% -------------------------------------------------------------------------
ax.Title.String='';
ax.Subtitle.String='';
ax.Subtitle.FontAngle='italic';
ax.TitleHorizontalAlignment='center';
% ax.XLabel.String='X-Axes';
% ax.XLabel.FontSize=16;
% ax.YLabel.String='Y-Axes';
% ax.YLabel.FontSize=16;
% legend('off');

% 刻度线
% -------------------------------------------------------------------------
ax.TickDirMode='auto';
ax.TickDir='in';
ax.TickLength=[0.015 0.025];
ax.TickLabelInterpreter='tex';

% 标尺(x坐标轴范围及x轴线、刻度值和标签的颜色)
% -------------------------------------------------------------------------
ax.XLimMode='manual';           ax.YLimMode='manual';
ax.XLim=[0 400];                ax.YLim=[0 200];
ax.XLimitMethod='tickaligned';  ax.YLimitMethod='tickaligned';
ax.XAxisLocation='bottom';      ax.YAxisLocation='left';
ax.XColorMode='manual';         ax.YColorMode='manual';
ax.XColor='k';                  ax.YColor=[0 51 186]/255;
ax.XDir='normal';               ax.YDir='normal';
ax.XScale='linear';             ax.YScale='linear';

% 刻度值和刻度值标签
% -------------------------------------------------------------------------
ax.XTickMode='manual';          ax.YTickMode='manual';
ax.XTick=0:100:400;             ax.YTick=0:50:200;
ax.XTickLabelMode='auto';       ax.YTickLabelMode='auto';
% ax.XTickLabel={'-3\pi','2\pi','-\pi','0','\pi','2\pi','3\pi'};
ax.XTickLabelRotation=0;        ax.YTickLabelRotation=0;
ax.XMinorTick='on';            ax.YMinorTick='on';

% X轴和y轴网格线的设置
% -------------------------------------------------------------------------
ax.XGrid='off';                  ax.YGrid='off';
ax.Layer='bottom';
ax.GridLineStyle='-';
ax.GridColorMode='manual';
ax.GridColor=[0.15 0.15 0.15];
ax.GridAlphaMode='auto';
ax.GridAlpha=0.15;
ax.XMinorGrid='off';            ax.YMinorGrid='off';
ax.MinorGridLineStyle=':';
ax.MinorGridColorMode='manual';
ax.MinorGridColor=[0.1 0.1 0.1];
ax.MinorGridAlphaMode='auto';
ax.MinorGridAlpha=0.25;

hold on;
yyaxis right;
p2 = plot(Xpump,Yeffi);

% 线条颜色和样式
p2.Color='r';
p2.LineStyle='-';
p2.LineWidth=3;
p2.LineJoin='round';
% 标记
p2.Marker='s';
p2.MarkerIndices=1:length(Yeffi);
p2.MarkerSize=8;
p2.MarkerEdgeColor='r';
p2.MarkerFaceColor='r';

ylabel('opt-opt efficiency (%)');

ax=gca;
% 坐标轴字体
% -------------------------------------------------------------------------
ax.FontName='Helvetica';    % 'Helvetica' or 'Arial'
ax.FontWeight='bold';
ax.FontSizeMode='auto';
ax.FontSize=20;
ax.FontAngle='normal';
ax.LabelFontSizeMultiplier=1.1;
ax.TitleFontSizeMultiplier=1.1;
ax.FontUnits='points';
ax.FontSmoothing='on';
ax.Color=[1 1 1];
ax.LineWidth=2;
ax.Box='on';

% 标签
% -------------------------------------------------------------------------
ax.Title.String='';
ax.Subtitle.String='';
ax.Subtitle.FontAngle='italic';
ax.TitleHorizontalAlignment='center';
% ax.XLabel.String='X-Axes';
% ax.XLabel.FontSize=16;
% ax.YLabel.String='Y-Axes';
% ax.YLabel.FontSize=16;
% legend('off');

% 刻度线
% -------------------------------------------------------------------------
ax.TickDirMode='auto';
ax.TickDir='in';
ax.TickLength=[0.015 0.025];
ax.TickLabelInterpreter='tex';

% 标尺(x坐标轴范围及x轴线、刻度值和标签的颜色)
% -------------------------------------------------------------------------
ax.XLimMode='manual';           ax.YLimMode='manual';
ax.XLim=[0 400];                ax.YLim=[0 70];
ax.XLimitMethod='tickaligned';  ax.YLimitMethod='tickaligned';
ax.XAxisLocation='bottom';      % ax.YAxis(2).Location='left';
ax.XColorMode='manual';         ax.YColorMode='manual';
ax.XColor='k';                  ax.YColor='r';
ax.XDir='normal';               ax.YDir='normal';
ax.XScale='linear';             ax.YScale='linear';

% 刻度值和刻度值标签
% -------------------------------------------------------------------------
ax.XTickMode='manual';          ax.YTickMode='manual';
ax.XTick=0:100:400;             ax.YTick=0:10:70;
ax.XTickLabelMode='auto';       ax.YTickLabelMode='auto';
% ax.XTickLabel={'-3\pi','2\pi','-\pi','0','\pi','2\pi','3\pi'};
ax.XTickLabelRotation=0;        ax.YTickLabelRotation=0;
ax.XMinorTick='on';             ax.YMinorTick='on';

% X轴和y轴网格线的设置
% -------------------------------------------------------------------------
ax.XGrid='off';
ax.YGrid='off';
ax.Layer='bottom';
ax.GridLineStyle='-';
ax.GridColorMode='manual';
ax.GridColor=[0.15 0.15 0.15];
ax.GridAlphaMode='auto';
ax.GridAlpha=0.15;
ax.XMinorGrid='off';
ax.YMinorGrid='off';
ax.MinorGridLineStyle=':';
ax.MinorGridColorMode='manual';
ax.MinorGridColor=[0.1 0.1 0.1];
ax.MinorGridAlphaMode='auto';
ax.MinorGridAlpha=0.25;

% 注释对象
ar1=annotation('arrow');
ar1.Color='r';
ar1.LineStyle='-';
ar1.LineWidth=3;
ar1.HeadStyle='cback1';
ar1.HeadLength=10;
ar1.HeadWidth=10;
ar1.Units='normalized';
ar1.X=[0.7231 0.9018];
ar1.Y=[0.7146 0.7146];

ar2=annotation('arrow');
ar2.Color=[0 51 186]/255;
ar2.LineStyle='-';
ar2.LineWidth=3;
ar2.HeadStyle='cback1';
ar2.HeadLength=10;
ar2.HeadWidth=10;
ar2.Units='normalized';
ar2.X=[0.4170 0.1367];
ar2.Y=[0.3318 0.3318];

% 插入No.1文本框
t1=annotation('textbox');

t1.Interpreter='tex';
t1.String='{\fontsize{32}\eta}_{\it{\fontsize{16}slope}}= 67.24%'; % 文本框的内容
t1.Color=[0 51 186]/255;

t1.FontName='Helvetica';
t1.FontUnits='points';
t1.FontSize=24;         % 文本框字体大小
t1.FontWeight='bold';
t1.FontAngle='normal';

t1.FitBoxToText='off';
t1.EdgeColor='none';           % 文本框框线颜色
t1.BackgroundColor='none';
t1.FaceAlpha=1;
t1.LineStyle='-';
t1.LineWidth=0.5;
t1.Margin=5;

t1.Units='normalized';
t1.Position=[0.35 0.18 0.3 0.1]; % 文本框的位置
t1.HorizontalAlignment='center';
t1.VerticalAlignment='top';

% 插入No.2文本框
t2=annotation('textbox');

t2.Interpreter='tex';
t2.String='{\fontsize{32}\eta}_{\it{\fontsize{16}opt.-opt.}}= 54.26%'; % 文本框的内容
t2.Color='r';

t2.FontName='Helvetica';
t2.FontUnits='points';
t2.FontSize=24;         % 文本框字体大小
t2.FontWeight='bold';
t2.FontAngle='normal';

t2.FitBoxToText='off';
t2.EdgeColor='none';           % 文本框框线颜色
t2.BackgroundColor='none';
t2.FaceAlpha=1;
t2.LineStyle='-';
t2.LineWidth=0.5;
t2.Margin=5;

t2.Units='normalized';
t2.Position=[0.42 0.70 0.3 0.1]; % 文本框的位置
t2.HorizontalAlignment='center';
t2.VerticalAlignment='top';

% export_fig(f,'C:\Users\dai19\Desktop\test40','-pdf','-r600');
export_fig 'C:\Users\dai19\Desktop\test41' '-pdf' -r600
altmany commented 2 years ago

Fixed in latest release