필터 지우기
필터 지우기

y-Label cut off by exportgraphics()

조회 수: 78 (최근 30일)
Stefan M
Stefan M 2023년 2월 6일
이동: Voss 2024년 7월 6일
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
Garrett Mitchener
Garrett Mitchener 2024년 3월 13일
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.
Ebgert
Ebgert 2024년 7월 6일
이동: Voss 2024년 7월 6일
This is still a problem and absolutely should not stll require a convoluted workaround for such a basic functionality.

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

채택된 답변

Aman
Aman 2023년 2월 14일
Hi,
I understand that you are trying to download the graphic content in a tightly cropped format, but in your case, it is cropping the “ylabel”. To rectify this, you can draw a suitable size rectangle around your content which will prevent cropping of your “ylabel” by the “exportgraphics” function. You can visit the below link for the reference.
  댓글 수: 1
Stefan M
Stefan M 2023년 2월 15일
Hi Aman,
thanks for the answer. I found that link myself (see my first comment). I fixed my figures using this workaround but wanted to keep the question open, to see, if there is any general setting or code mistake I made to produce the too tight cropping.
Do you have any idea, why exportgraphics does cut the ylabel in some cases, but not in others?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by