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')
  1 件のコメント
Niklas Kurz
Niklas Kurz 2020 年 7 月 4 日
Many thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by