Change figure legend horizontal spacing

조회 수: 165 (최근 30일)
Matthew
Matthew 2019년 1월 8일
편집: Karl_469 2022년 11월 17일
example legend.PNG
In the attached example legend, there's too much whitespace between the first marker (red) and the first legend entry (gefeuert). There's not enough whitespace between the first legend entry and the second marker.
How do I change these two things:
  1. Space between a marker and a marker entry
  2. Space between the first legend entry and the second marker
Thanks!
  댓글 수: 1
Shubham Gupta
Shubham Gupta 2019년 1월 9일
About your 2nd point, I believe increasing width of the legend should increase the spacing between the 2 entries.
I am not sure about the 1st point though, I hope it helps in someway. Cheers

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

답변 (2개)

nbrake
nbrake 2019년 10월 24일
편집: nbrake 2019년 10월 24일
L = legend;
I believe the property you are looking for is:
L.ItemTokenSize
^ This is a 2-vector. The first element specifies the distance between the legend symbol and the text. If you have errorbars, the second element specifies the height of those errorbars in the legend. I believe the default is [30,30]. If you want to reduce the distance between the marker and text:
L.ItemTokenSize(1) = 10;
  댓글 수: 1
Matthew
Matthew 2019년 10월 26일
Thanks! This certainly fixes 'half' of it, in other words, this fixes the spacing between the marker and the text.
Is there a way to space the two entries further apart, as well?

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


dpb
dpb 2019년 1월 9일
  1. Something legend gives no control of directly
  2. Increase the width of the legend will spread them out
hLg=legend('gefeuert','nicth gefeuert','Orientation','horiz');
pos=hLg.Position; % retrieve existing position
pos(3)=1.5*pos(3); % increase width value 50% in position 4-vector
hLg.Position=pos; % set new position
Beyond that, the legend object is almost totally opaque to the end user, unfortunately.
  댓글 수: 1
Karl_469
Karl_469 2022년 11월 17일
편집: Karl_469 2022년 11월 17일
By changing the position, I can only increase the spacing.
Unfortunatley, I want to reduce the spacing in which case my position Input is just ignored.
Has there been updates on this problem since 2019?
How to push this to Mathworks to be changed?
It is pretty basic and intuitive to have control over the legend, yet, Matlab causes troubles over and over. Just a few examples where you have to find often ridiculous solutions that usually cause some subsequent issues:
1) in matlab, it makes a difference whether to use plot or scatter regarding the legend, because with scatter you cannot directly control the legend(!) marker icon size (https://ch.mathworks.com/matlabcentral/answers/50250-how-can-i-change-the-marker-size-in-legend)
2) you cannot directly chose the objects to be displayed in the legend (obviously, Mathworks cannot think of a case where you might select just a few objects, not all, really?! )(https://ch.mathworks.com/matlabcentral/answers/455329-remove-data-elements-of-the-legend-from-figure)
3) apparantly, you have no control on the legend spacing. Matlab is by default very generous with white spacings and whats better to have in a figures than white space...(https://ch.mathworks.com/matlabcentral/answers/367343-how-to-decrease-the-size-of-the-legend-in-a-figure)
Above that, Matlab makes it complicated to export figures in a controlled way. Thus, you have to use export_fig and matlab2tikz/matlab2tikz for over 8-10 years now. Matlab exportgraphics is ok-ish but it took mathwork like 8 years to come up with it and in my case, I still have to use export-fig.

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

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by