61 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sim am 14 Sep. 2020
Kommentiert: Sim am 23 Sep. 2020
Hi, How can I align the Legend Title to the Legend body (variables, etc..)? Maybe left-aligned ?
5 Kommentare 3 ältere Kommentare anzeigen3 ältere Kommentare ausblenden
3 ältere Kommentare anzeigen3 ältere Kommentare ausblenden
Adam Danz am 14 Sep. 2020
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/593461-align-the-legend-title-to-the-legend-body#comment_1008439
Tough one. The title property for legends doesn't have a HorizontalAlignment property nor a position property.
If you add space before the legend title (ie, " my title"), the title will be offset to the right. But if you add space after the title, the space is ignored. I haven't looked any deeper than that, though.
Sim am 14 Sep. 2020
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/593461-align-the-legend-title-to-the-legend-body#comment_1008541
Bearbeitet: Sim am 14 Sep. 2020
Thanks a lot for your nice reply Adam :-)
...I tried to add some space already, but it did not work :-)
(However, in such an historical and cool software, I think that a property as the alignment of the legend content should be something quite 'basic'......)
Adam Danz am 14 Sep. 2020
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/593461-align-the-legend-title-to-the-legend-body#comment_1008565
If you contact tech support, they will either suggest a workaround or they may put it on their list of things to improve.
https://www.mathworks.com/support/contact_us.html
Maybe there's an undocumented method I'm not aware of.
Sim am 14 Sep. 2020
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/593461-align-the-legend-title-to-the-legend-body#comment_1008787
Bearbeitet: Sim am 14 Sep. 2020
Thanks a lot! Just submitted to the MATLAB support :)
Adam Danz am 14 Sep. 2020
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/593461-align-the-legend-title-to-the-legend-body#comment_1008859
I'd be interesting in whatever you find.
Melden Sie sich an, um zu kommentieren.
Melden Sie sich an, um diese Frage zu beantworten.
Antworten (1)
Ayush Gupta am 18 Sep. 2020
In MATLAB Online öffnen
The legend title is by-default left aligned to legend body. Refer to the code below which generates the following picture and read the documentation on how to add legend title, here.
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)
hold on
y2 = cos(2*x);
plot(x,y2)
hold off
lgd = legend('cos(x)','cos(2x)');
title(lgd,'My Legend Title')
6 Kommentare 4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden
4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden
Adam Danz am 18 Sep. 2020
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/593461-align-the-legend-title-to-the-legend-body#comment_1014424
I don't have access to Matlab at the moment but I'm fairly certain the default alignment is center for legend titles.
If you add space to the beginning of the title you can offset it rightward but if you add space to the right of the title the spaces are trimmed and the title remains centered. At least this is what I remember finding when I was playing around with this in r2019b.
Sim am 18 Sep. 2020
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/593461-align-the-legend-title-to-the-legend-body#comment_1014454
Bearbeitet: Sim am 18 Sep. 2020
Thanks Ayush,
I was aware about the default alignement. However, try to get something similar to the text I wrote in my example (with relatevily long texts) and you will find out that legend title and body will lose the alignment.
Just for your knowledge, I opened a ticket to the MATLAB support service with "technical support case" #04491718 regarding 'Suggestion for an improvement'.
@Adam: I experienced what you described in R2019b.....
Adam Danz am 20 Sep. 2020
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/593461-align-the-legend-title-to-the-legend-body#comment_1016848
@Sim
I just saw that as of r2020b you can control the justification of titles but I haven't tested whether or not this works with legend titles.
Sim am 23 Sep. 2020
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/593461-align-the-legend-title-to-the-legend-body#comment_1021648
Bearbeitet: Sim am 23 Sep. 2020
Oh thanks a lot, I will try to download r2020b and check that feature :)
Btw, in case it work I should accept your answer, but there is not any button for it (its just besides Ayhus Gupta)
Adam Danz am 23 Sep. 2020
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/593461-align-the-legend-title-to-the-legend-body#comment_1021735
I've checked since I made that comment and legend titles are not supported with the updated features.
In fact, I wrote a Community Highlights about these new features.
https://www.mathworks.com/matlabcentral/discussions/highlights/133180-new-in-r2020b-subtitles-title-label-alignment
Title alignment is controlled by the new "TitleHorizontalAlignment" property of axes. Legends still do not have such a property.
Sim am 23 Sep. 2020
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/593461-align-the-legend-title-to-the-legend-body#comment_1021750
Oh cool, thanks a lot for highlighting that feature... So, if not working for the Legends, my MATLAB ticket opening was worth it :)
Melden Sie sich an, um zu kommentieren.
Melden Sie sich an, um diese Frage zu beantworten.
Siehe auch
Kategorien
MATLABGraphicsFormatting and AnnotationLabels and AnnotationsLegend
Mehr zu Legend finden Sie in Help Center und File Exchange
Tags
- legend title
- align
- legend body
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Es ist ein Fehler aufgetreten
Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asien-Pazifik
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Kontakt zu Ihrer lokalen Niederlassung