필터 지우기
필터 지우기

How to change the bar length in a bar graph legend?

조회 수: 9 (최근 30일)
Corymbiamaculata
Corymbiamaculata 2022년 3월 22일
이동: the cyclist 2023년 11월 10일
There was already a similar question asked - and answered - in 2009 (link), but the solution no longer works in the newer releases.
Thanks in advance!

답변 (1개)

Yongan
Yongan 2023년 11월 10일
이동: the cyclist 2023년 11월 10일
It could be changed by using 'ItemTokenSize' parameter. Please refer to the sample code below:
% Create a bar graph
x = 1:5;
y = [10 15 8 12 9];
bar(x, y);
% Get the handle to the legend object
legendHandle = legend('Data');
% Set the desired length of the bar in the legend axes
desiredLength = 20; % Modify this value as needed
% Set the desired height of the bar in the legend axes
desiredHeight = 10; % Modify this value as needed
% Adjust the ItemTokenSize property of the legend
set(legendHandle, 'ItemTokenSize', [desiredLength desiredHeight]);

카테고리

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

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by