saved pdf file doesn't look like figure

12 vues (au cours des 30 derniers jours)
Leo Simon
Leo Simon le 18 Avr 2016
Commenté : Jerry Malone le 1 Sep 2023
When I save a figure as a pdf file, the pdf version adds spaces which aren't in the original. The two images attached illustrate the problem. The first image is a screenshot of my matlab figure.
The second image is a screenshot of the pdf version.
As you can see there's a huge gap before the gamma in the title, and also before the exponents in the ylabel for the third subplot. I get exactly the same problem using matlab's print command, i.e.,
print(gcf,'-dpdf',printName)
and using the code save2pdf, which I downloaded from this forum
save2pdf(printName)
Any advice as to how to fix this problem would be most appreciated!
  3 commentaires
Leo Simon
Leo Simon le 21 Avr 2016
I'm using R2016a
Jerry Malone
Jerry Malone le 1 Sep 2023
Has this problem ever been solved?

Connectez-vous pour commenter.

Réponse acceptée

Richard Quist
Richard Quist le 9 Mai 2016
Modifié(e) : Richard Quist le 9 Mai 2016
This sounds like a known bug - see this bug report.
  2 commentaires
Leo Simon
Leo Simon le 9 Mai 2016
Modifié(e) : Leo Simon le 9 Mai 2016
Thanks Richard. opengl works as you indicated, provided I specify it as an option to the figure command. However, I'd like it to be my default. So I put opengl rendering in my startup script with the line
set(0, 'DefaultFigureRenderer', 'OpenGL');
and indeed, when I open matlab
get(gcf,'Renderer')
returns
opengl
However, this renderer is somehow not being applied to the gcf when I plot a figure without first calling the figure command, i.e., I have the same problem as before printing titles. Can anybody suggest why it's not possible to apply the default Rendering? Or maybe it's being applied, but somehow not fixing the pdf bug when specified as the default?
More generally, I looked all over the web for a site which would tell me the pros and cons of setting opengl. From this mathworks [age, it looks like it helps most of the time, except if you are zooming, but it would be nice if mathworks could provide something normal people could understand.
Richard Quist
Richard Quist le 17 Mai 2016
Leo,
The short answer: instead of setting the DefaultFigureRenderer property to 'opengl' in startup.m, set the DefaultFigureRendererMode property to 'manual'.
set(0, 'DefaultFigureRendererMode', 'manual');
This will cause the print engine to use whatever the figure Renderer is when generating output; since the default in MATLAB since R2014b is to use OpenGL, the generated output will be rasterized (image).
There are alternative approaches as well, and I describe those down below.
Why Does Setting the Renderer Directly Work, but Setting DefaultFigureRenderer Doesn't?
Setting the Renderer property directly on a figure also causes the figure's RendererMode property to be changed to 'manual'... and when the RendererMode property is manual the print engine uses the figure's Renderer when generating output.
Setting the DefaultFigureRenderer in startup.m as you are doing does NOT change the mode ... which is why that didn't work for you the way you hoped it would.
Alternatives to Force Print to Use OpenGL
To force the print engine to use OpenGL you can do any of the following:
  1. call print and specify -opengl as one of the arguments: print -opengl -dpdf output.pdf
  2. manually set the figure's renderer to opengl (as noted above, this also causes the figure's RendererMode property to become 'manual'): set(gcf, 'Renderer', 'opengl');
  3. set the DefaultFigureRendererMode to 'manual'
Note: you can use these same methods to also force the use of painters, although for the last item you would also want to set the DefaultFigureRenderer to 'painters'
Information About MATLAB's Renderers
There's a brief discussion of the two renderers that are available in MATLAB in the documentation here.
  • OpenGL rendering is most often implemented in hardware and provides fast performance. Using OpenGL when printing will always generate rasterized (image) output.
  • Painters is implemented in software, so it can be slower, especially for 3D scenes. It is the only renderer MATLAB can use when generating vectorized output
Information About the Renderer Used When Printing
The documentation for the print command, here, has an entry describing the formattype argument and within that is a Vector Graphics File section that talks about the Renderer used when printing.

Connectez-vous pour commenter.

Plus de réponses (1)

Bharath Rangaswamy
Bharath Rangaswamy le 21 Avr 2016
Hi Leo,
Open MATLAB, goto preferences>”Figure copy template”>”Copy options” – In this settings you get 3 options for “Clipboard format” please change this option to “Bitmap”.
Then try to save it again. This might help.
-Bharath
  3 commentaires
Leo Simon
Leo Simon le 21 Avr 2016
Sorry, I didn't finish attaching, this time it's there
Richard Quist
Richard Quist le 17 Mai 2016
The "Copy Options" preference panel is only available on Windows.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by