Why does OpenGL renderer keep white space around figures when saving?

조회 수: 2 (최근 30일)
Nicholas Richmond
Nicholas Richmond 2017년 8월 22일
편집: Nicholas Richmond 2017년 11월 28일
Given the same figure, choosing the OpenGL renderer over the Painters renderer produces superfluous white space when saving the figure. Here's a simple example:
% create a figure with full height and width
myplot = figure('units','normalized','outerposition',[0 0 1 1]);
set(gca,'Position',[0 0 1 1])
subplot(2,1,1);
x = linspace(0,10);
y1 = sin(x);
plot(x,y1)
subplot(2,1,2);
y2 = sin(5*x);
plot(x,y2)
set(myplot,'Renderer','opengl','GraphicsSmoothing','on');
saveas(myplot,'myfigure-opengl', 'epsc');
set(myplot,'Renderer','painters','GraphicsSmoothing','on');
saveas(myplot,'myfigure-painters', 'epsc');
The figure rendered with OpenGL looks like this (when opened in GIMP or similar):
The figure rendered with painters looks like this (when opened in GIMP or similar):
The plot rendered with Painters correctly snaps to the subplots, but I need to use the OpenGL renderer for my EPS figures in order to accommodate LaTeX characters which do not format correctly with Painters. What can I do to make OpenGL save the figures without the border white space?

답변 (1개)

Jan
Jan 2017년 8월 22일
The EPS export considers the PaperPosition and not the screen dimensions of the figure. Why this is different for OpenGL and Painters is not clear to me, but differences are expected:
OpenGL creates pixel graphics, while the Painters renderer can export vector data for the EPS export. Therefore you see a kind of screen shot in the EPS created using the OpenGL renderer.
  댓글 수: 1
Nicholas Richmond
Nicholas Richmond 2017년 8월 22일
Interesting! Your response led me to try adding in a PaperPosition specification as follows:
set(myplot,'Renderer','opengl','GraphicsSmoothing','on',...
'PaperUnits','normalized','PaperPosition',[0 0 1 1]);
saveas(myplot,'myfigure-opengl', 'epsc');
...but the border white space remains the same. I am hopeful that there is a solution which allows the proper LaTeX formatting afforded by OpenGL and the proper figure sizing afforded by Painters. Perhaps I should ask a separate question about LaTeX formatting with Painters in case that is easier to solve than the OpenGL figure sizing issue.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by