y-Label cut off by exportgraphics()
Mostrar comentarios más antiguos
The description of the function exportgraphics says, that it produces a tightly cropped image. In my case it produces a tightly cropped PDF which is unfortunately a little bit too tight at the y-label. I tried rearranging the figure within the window, but exportgraphics does not change its output (which is the intended functionality). Unfortunately, in my case, this leads to a cut image.
The code:
set(groot,'defaultAxesFontName','PT Sans')
p = figure('Position', [455,503,879,400]);
ylabel('Label Example: i C', 'FontWeight', 'bold')
set(gca, 'FontSize', 14)
exportgraphics(p,'label_example.pdf','BackgroundColor','none','ContentType','vector');
produces a slightly cut off y-label as you can see in this picture:

The large C as well as the small i are cut off at the top. The font 'PT Sans' is only needed to produce the exact image, but the problem is also happening with other fonts. At the other borders of my figure exportgraphics adds a small white space, as I would expect. This only happens for the y-label.
If you need further information, please comment and I will try to give it to you as soon as possible. Thanks in advance for the help.
Best regards
Stefan
9 comentarios
Stefan M
el 7 de Feb. de 2023
Jonas
el 8 de Feb. de 2023
i cannot reproduce your problem, my pdf is fine. I am running 2022a
try switching your Renderer
try plotting into a tiledlayout, that sometimes helped me to fix some gitches
Stefan M
el 8 de Feb. de 2023
Jonas
el 8 de Feb. de 2023
you can change your renderer using
set(gcf,'Renderer','opengl')
or
set(gcf,'Renderer','painters')
you can also try to update your graphics card driver
Stefan M
el 8 de Feb. de 2023
Jonas
el 9 de Feb. de 2023
yes, I also used 14 as font size. I just copy pasted your code onto my machine. Did you try a tiledlayout for printing, sometimes this helped me:
set(groot,'defaultAxesFontName','PT Sans')
p = figure('Position', [455,503,879,400]);
tiledlayout(1,1); nexttile();
ylabel('Label Example: i C', 'FontWeight', 'bold')
set(gca, 'FontSize', 14)
exportgraphics(p,'label_example.pdf','BackgroundColor','none','ContentType','vector');
Stefan M
el 9 de Feb. de 2023
Garrett Mitchener
el 13 de Mzo. de 2024
I ran into something like this with labels getting cut off, and I noticed the figure window would sort of blink or hesitate as functions like xlabel() and xlim() are applied. I think it was catching up on the plotting process, and exportgraphics() was getting called before it had settled to its final state. I added pause(2) between the last command that affected the figure and exportgraphics, and it's no longer cutting off my axis labels.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
