Rendering error - print large size pdf

10 次查看(过去 30 天)
TP
TP 2019-4-30
编辑: TP 2020-1-27
Edit: The code works with Matlab 2015b but but produces the described error with Matlab 2018b (Windows 7).
I am trying to print a large size pdf (A2) containing vector elements on top of a simple imagesc (see minimal example below). The code works when printing the figure as a raster, but not when printing as a vector (see error message below). I do not mind if the "imagesc" is saved in a raster format, but I would like to keep the overlaying lines and axes in vector format. Is there a BUILT-IN solution for this problem?
Minimal (non-)working example:
clear all; close all; clc
dx_figure=59.4; dy_figure=42; % A2 landscape format in centimeters (cm)
margin=2.5; % in cm; allow for margin between axes and figure
f_handle=figure;
set(f_handle,'visible','off'); % make figure invisible on screen to avoid automatic resizing
set(f_handle,'units','centimeters','position',[0 0 dx_figure dy_figure]); % set figure at true size
axes('position',[margin/dx_figure margin/dy_figure (dx_figure-2*margin)/dx_figure (dy_figure-2*margin)/dy_figure]) % create axes in normalized units (bug when working in cm)
imagesc(rand(10,10)); % when this line is commented out, the figure is successfully printed in both raster or vector format
hold on
plot([0 10],[0 10],'linewidth',5); % vector part of figure
set(f_handle,'paperunits','centimeters','paperpositionmode','manual','papersize',[dx_figure dy_figure],'paperposition',[0 0 dx_figure dy_figure]);
print(f_handle,'-dpdf','image_vector'); % print in vector format (does not work)
%print(f_handle,'-dpdf','image_raster','-opengl'); % print in raster format (works)
Error message:
Warning: An error occurred while drawing the scene: Unidentified trouble during rendering
> In defaulterrorcallback (line 12)
In matlab.graphics.internal.mlprintjob/setPaintDisabled
In alternatePrintPath
In alternatePrintPath
In onCleanup/delete (line 60)
In alternatePrintPath
In print (line 82)
  1 个评论
Anders Svensson
Anders Svensson 2019-8-31
I have a very similar problem. A code that worke perfect in 2015b experience the described problem in 2017b. To mee the error is a bit random. It does not happen all the time. Running the same script with the same input generates the error on approximately 20% of my 2D plots. It appears as if the error is more frequent on larger images.

请先登录,再进行评论。

回答(1 个)

Luis J Gilarranz
Luis J Gilarranz 2020-1-25
Maybe this helps ;-)
Let us know, if using
opengl software
as suggested in this question solves the problem, Mathworks should consider this as a bug.
  1 个评论
TP
TP 2020-1-27
编辑:TP 2020-1-27
Thanks, I just tried but it does not change the problem.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by