Why is my subplot legend empty when I run my script using MATLAB 2021b but it is okay when run with R2020b?

조회 수: 4 (최근 30일)
subplot(1,2,1);
% bring up legend outside of plot area and move to desired position
legend_handle = legend('','','','','','','','');
set(legend_handle,'Location','EastOutside'); %% % <<<<< The legend appears here for R2020b but NOT for R2021b
set(legend_handle,'Orientation','vertical');
set(legend_handle,'FontSize',8);
% move subplot to the left in figure and resize width
pos = get(gca,'Position'); % natural positions for subplot 0.13, 0.11, 0.2597, 0.815
set(gca,'Position',pos); % move subplot to the left in figure and resize width
Legend_Sting = {'Travel Range','Retract Stops','Insert Stops','Offsets','SW Retract Limit','SW Insert Limit','Max Retract Limit','Min Insert Limit',''};
% move the legend position so it is to the right of plot near bottom of figure
set(legend_handle,'String',Legend_Sting);
Legend_Position = [0.52,0.08,0.2,0.2];
set(legend_handle,'Position',Legend_Position);

채택된 답변

Walter Roberson
Walter Roberson 2022년 8월 17일
legend_handle = legend('','','','','','','','');
At some point, legend() changed so that specifying '' as the legend string caused the legend to be turned off for that entry, rather than creating a legend entry that happened to have a corresponding character vector.
Thus you are turning off the legend for 8 entries -- so those entries do not exist for you to manipulate the string property.
When I test your code in R2022a, an empty legend box is generated.
  댓글 수: 1
John Lauria
John Lauria 2022년 8월 17일
Thank you Walter. I replaced the empty strings which at this point were only placeholders with some real ascii characters and that fixed my problem!
legend_handle = legend('a','b','c','d','e','f','g','h'); % placeholders

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by