customize legend: extra legend entry

33 次查看(过去 30 天)
On a first isight I didn't find the answere, but it might excist already. However to shorten things: I got the following legend:
legend({'Fit: $\arccos\left(\frac{\omega_0^2 - \omega^2}{\sqrt{(2\,\delta\,\omega)^2 + (\omega_0^2 - \omega^2)^2}}\right)$','Spulenstrom: 0,25 A','Fit:','Spulenstrom: 0,50 A','Fit','Spulenstrom: 1,50 A','Fit'},'Interpreter','latex','FontSize',16
Actually the first item doesn't belong to any graph, I made it visible by adding
fplot(w,'color',[1 1 1])
in front. However this isn't satisfying me, bc the entry is "sticking out". How can I indent it?

采纳的回答

the cyclist
the cyclist 2020-7-4
"The first item doesn't belong to any graph" immediately indicates to me that this text does not belong in the legend, for two reasons:
  • Theoretically, it does not make sense from a "grammar of graphics" approach.
  • Pragmatically, whoever looks at the graphic and legend expects everything in the legend to be linked to a data element, so the viewer is going to be confused (if only briefly)
So, it is no surprise to me that it would be difficult to make this work in MATLAB. (I don't know of a way to do it.)
I would think of this text as an annotation to the legend, and would therefore would create it separately, but nearby the legend. Here is one possible way to do that. (I just made up some nonsense data.)
rng default
figure
plot(rand(6))
legend({'Spulenstrom: 0,25 A','Fit:','Spulenstrom: 0,50 A','Fit','Spulenstrom: 1,50 A','Fit'},'Interpreter','latex','FontSize',16)
annotation('textbox',[0.57,0.5,0.1,0.1],'String', ...
'Fit: $\arccos\left(\frac{\omega_0^2 - \omega^2}{\sqrt{(2\,\delta\,\omega)^2 + (\omega_0^2 - \omega^2)^2}}\right)$', ...
'BackgroundColor','white','LineStyle','-','Fontsize',12,'Interpreter','latex')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by