필터 지우기
필터 지우기

Is there a way to fix a legend to an exact size and position?

조회 수: 9 (최근 30일)
Daniel Pusicha
Daniel Pusicha 2022년 8월 3일
댓글: Daniel Pusicha 2022년 8월 3일
Here is my setting (Code snippets simplified for illustration purposes):
I have a figure with a legend that uses the LaTeX interpreter.
figure
plot(my_data,'LineWidth',2)
legend('SMO $\sigma = 10^{-3}$','SMO $\sigma = 10^{-2}$','SMO $\sigma = 10^{-1}$', ...
'HGO $\sigma = 10^{-3}$','HGO $\sigma = 10^{-2}$','HGO $\sigma = 10^{-1}$', ...
'Interpreter','latex','NumColumns',3,'Location','north')
When exporting the figure as an SVG I change the interpreter to 'none'. This seems necessary to me because I want to use the Inkscape functionality to export SVG's to .pdf_tex (see: here), but when using the LaTeX interpreter this didn't work in my experience.
fig = gcf;
ax = gca;
pos = ax.Legend.Position; % Remember the legend position before the interpreter is changed
ax.Legend.Interpreter = 'none'; % Change the interpreter
ax.Legend.Position = pos; % Set the remembered position -> Unfortunately, this didn't help
print(fig,'my_figure_name','-dsvg') % Export as SVG
When including the exported figure in my tex project it is rendered using an LaTeX interpreter. Unfortunately, the legend now occupies to much space (as this was needed for all the LaTeX commands during the export).
So here is my question:
Is there a way to fix my legend to an exact size and position so it does not move when changing the interpreter?
Thanks for any help in advance :)
  댓글 수: 4
Dyuman Joshi
Dyuman Joshi 2022년 8월 3일
Maybe decreasing the font size might help.
x=reshape(linspace(-pi,pi,48),6,[]);
figure
plot(sin(x),'LineWidth',2)
legend('SMO $\sigma = 10^{-3}$','SMO $\sigma = 10^{-2}$','SMO $\sigma = 10^{-1}$', ...
'HGO $\sigma = 10^{-3}$','HGO $\sigma = 10^{-2}$','HGO $\sigma = 10^{-1}$', ...
'NumColumns',3,'Location','north', 'FontSize', 7.5)
Daniel Pusicha
Daniel Pusicha 2022년 8월 3일
Thanks, that's a good idea and helped so there is at least a workaround.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by