Is there a way to fix a legend to an exact size and position?
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Dyuman Joshi
il 3 Ago 2022
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)
Risposte (0)
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!