customize legend: extra legend entry

조회 수: 33 (최근 30일)
Niklas Kurz
Niklas Kurz 2020년 7월 4일
댓글: Niklas Kurz 2020년 7월 4일
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