MATLAB Answers

customize legend: extra legend entry

조회 수: 9(최근 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?

  댓글 수: 0

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

채택된 답변

the cyclist
the cyclist 4 Jul 2020
"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
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)$', ...

  댓글 수: 1

Niklas Kurz
Niklas Kurz 4 Jul 2020
Many thanks!

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

추가 답변(0개)



Translated by